我有这个代码
$myNewClass->cars =& Orders_Car::GetRecords($myNewClass->searchString);
^
Run Code Online (Sandbox Code Playgroud)
在那&做什么 谢谢
它将变量更改为"通过引用传递".这与传递变量的副本相反.
有关详细信息,请参阅手册
一个常见的用途是foreach.
通常,foreach在可迭代数组或对象的副本上运行.
这意味着
$salad=array(1,2,3);
foreach ($salad as $leaf){
$leaf+=1;
}
echo $salad[0];// output: 1
foreach ($salad as &$leaf){
$leaf+=1;
}
echo $salad[0];// output: 2 because & made the assignment affect the original array
Run Code Online (Sandbox Code Playgroud)