note 75165 deleted from function.end by danbrown

From: Date: Wed, 15 Jun 2011 23:02:41 +0000
Subject: note 75165 deleted from function.end by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180580@lists.php.net to get a copy of this message
Note Submitter: Sven Arduwie ---- RE: mika dot stenberg at helsinki dot fi Your function array_set_current is flawed: function array_set_current(&$array, $key){ reset($array); while(current($array)){ if(key($array) == $key){ break; } next($array); } } Notice that current() cannot distinguish the end of an array from a boolean FALSE element value. For example, try this: $array = array(false, 'This', 'is', 'a', 'test'); array_set_current($array, 3); var_dump(current($array)); This will work: function array_set_current(&$array, $key) { reset($array); foreach ($array as $value) { if (key($array) === $key) { break; } } } Also, I prefer key($array) === $key over key($array) == $key.

« previous php.notes (#180580) next »