Quote:
Originally Posted by Fou-Lu
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).