note 102978 deleted from control-structures.foreach by googleguy
| From: | googleguy@php.net | Date: | Wed, 14 Nov 2012 22:22:25 +0000 |
| Subject: | note 102978 deleted from control-structures.foreach by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191948@lists.php.net to get a copy of this message | ||
Note Submitter: broshizzledizzle at gmail dot com
----
@benekastah
You are unintentionality misleading people.
Your code is the same as this:
<?php
$array = array('a', 'b', 'c', 'd');
foreach ( $array as $letter )
;
echo $letter;
?>
What I mean by this is that you execute the foreach loop but don't do anything with it. The
reason you can echo the last value in the array is because of the warning posted above:
"Reference of a $value and the last array element remain even after the foreach loop. It is
recommended to destroy it by unset()."