关联参数传递的使用方法

2026-02-18 15:14:01

1、方法一:


functionfoo(&$bar){
$bar.="andsomethingextra";
}
$str="ThisisaString,";
foo($str);
echo$str;//output:ThisisaString,andsomethingextra

echo"<br>";

关联参数传递的使用方法

2、方法二:


functionfoo1($bar){
$bar.="andsomethingextra";
}
$str="ThisisaString,";

foo1($str);


echo$str;//output:ThisisaString,

echo"<br>";

foo1(&$str);


echo$str;//output:ThisisaString,andsomethingextra
?>

猜你喜欢