note 75165 added to function.end

From: Date: Tue, 15 May 2007 20:43:29 +0000
Subject: note 75165 added to function.end
Groups: php.notes 
Request: Send a blank email to php-notes+get-126633@lists.php.net to get a copy of this message
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. ---- Server IP: 193.190.198.20 Probable Submitter: 213.118.91.83 ---- Manual Page -- http://www.php.net/manual/en/function.end.php Edit -- https://master.php.net/note/edit/75165 Del: integrated -- https://master.php.net/note/delete/75165/integrated Del: useless -- https://master.php.net/note/delete/75165/useless Del: bad code -- https://master.php.net/note/delete/75165/bad+code Del: spam -- https://master.php.net/note/delete/75165/spam Del: non-english -- https://master.php.net/note/delete/75165/non-english Del: in docs -- https://master.php.net/note/delete/75165/in+docs Del: other reasons-- https://master.php.net/note/delete/75165 Reject -- https://master.php.net/note/reject/75165 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126633) next »