foreach() & references
Posted: Wed Jun 23, 2004 11:51 am
I need to run through an array with a foreach loop, but I need to value which is passed from the foreach iteration to be a reference so that when I make a change, it will stick.
This is just an example. But when this foreach loop ends. Any value that was 1 is not changed to 2 because only a copy of the value of $selection was passed in, not a reference.
I've tried the following and only get parse errors:
Any ideas?
Code: Select all
foreach($selection as $select) {
if ($select == 1) {
$select = 2;
}
}I've tried the following and only get parse errors:
Code: Select all
foreach($selection as &$select) {
if ($select == 1) {
$select = 2;
}
}Code: Select all
foreach(&$selection as $select) {
if ($select == 1) {
$select = 2;
}
}