PHP Bug or my misunderstanding of the language?
<p>This is the code that I don't understand (as the output).</p><pre><br /><code><?php<br />$x = ['test1', 'test2', 'test3', 'test4'];<br />echo "First FOREACH\n";<br />foreach ($x as &$y)<br />{<br /> echo $y."\n";<br />}<br />echo "\n\nSecond FOREACH\n";<br />foreach ($x as $y)<br />{<br /> echo $y."\n";<br />}<br /><br />?><br /></code><br /></pre><p><strong>Output:</strong></p><pre><br /><code>First FOREACH<br />test1<br />test2<br />test3<br />test4<br /><br />Second FOREACH<br />test1<br />test2<br />test3<br />test3<br /></code><br /></pre><p>PS: I'm running it under:</p><pre><br /><code>php -v<br />PHP 5.6.11-1ubuntu3.1 (cli) <br />Copyright (c) 1997-2015 The PHP Group<br />Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies<br /> with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies<br /></code><br /></pre><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525495/php-bug-or-my-misunderstanding-of-the-language">http://ift.tt/1Vpgopj</a></h2>
Nhận xét
Đăng nhận xét