Home >Backend Development >PHP Tutorial >Outdoor research php foreach issues to pay attention to when using & and operator reference assignment
foreach can easily modify the elements of the array by adding & before $value, such as:
PHP code
Copy code The code is as follows:
foreach($arr as $value){
$value . = '4';
}
Copy the code The code is as follows:
$arr = array('a','b','c');
$arr2 = array('d', 'e', 'f');
foreach($arr as $value){//Used to use $value or $val
$value .= '4';
}
//Handle both After we finish the output in the page template, first output $arr2
foreach($arr2 as $value){//Usually use $value or $val
//echo $value;
}
//Then output $arr;
foreach($arr as $value){//Used to use $value or $val
echo $value, "n";
}
?>
Copy the code The code is as follows:
XML/HTML code
a4
b4
b4
Copy code The code is as follows:
Array
(
[0] => a4
[1] => b4
[ 2] => f
)
Copy code The code is as follows:
foreach($arr as $value){
$value .= '4';
}
unset($value);
The above introduces the issues that should be paid attention to when using & and operator reference assignment in outdoor research php foreach, including the content of outdoor research. I hope it will be helpful to friends who are interested in PHP tutorials.