View Single Post
Old 11-29-2012, 04:17 PM   PM User | #5
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
Hisss, don't use unset during a foreach. Altering arrays during traversals such as foreach or using iterators may cause undefined behaviour.
Would you say that in all cases?

I remember playing around with something or other like this..

PHP Code:


$array 
scandir($dir);

foreach(
$array as $key => $value) { if(strchr($value'.') { unset($key); }} 
It was meant to remove the files, and the initial "." and ".." from the directory scan. I don't use it at the moment, I'm still wondering if that was bad use of unset (scandir seems a little more predictable, your comment seemed like a catchall).
Custard7A is offline   Reply With Quote