Richard K Miller schreef: > Is this a bug in PHP? No > > <?php > $items = array('apple', 'banana', 'carrot'); > print_r($items); > foreach ($items as &$item) { } $item is now a reference to the last element of $items. > print_r($items); > foreach ($items as $item) { } And here, the foreach loop writes to $item for each element: thus assiging that value to the last element of $items. > print_r($items); > ?> > > // Output: > Array > ( > [0] => apple > [1] => banana > [2] => carrot > ) > Array > ( > [0] => apple > [1] => banana > [2] => carrot > ) > Array > ( > [0] => apple > [1] => banana > [2] => banana > ) > > Two bananas in the last set?! Not what I expected. You can fix your bug by using 'unset($item);' after the second foreach-loop.
-- Jille > > Richard > > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php