The 5th Annual China PHP Conference

Voting

Please answer this simple SPAM challenge: four plus four?
(Example: nine)

The Note You're Voting On

ivan at mailinator dot com
8 years ago
A little gotcha (be careful with references!):

<?php
$arr
= array('a'=>'first', 'b'=>'second', 'c'=>'third');
foreach (
$arr as &$a); // do nothing. maybe?
foreach ($arr as $a);  // do nothing. maybe?
print_r($arr);
?>
Output:

Array
(
    [a] => first
    [b] => second
    [c] => second
)

Add 'unset($a)' between the foreachs to obtain the 'correct' output:

Array
(
    [a] => first
    [b] => second
    [c] => third
)

<< Back to user notes page

To Top