note 101626 added to function.key

From: Date: Thu, 30 Dec 2010 19:29:33 +0000
Subject: note 101626 added to function.key
Groups: php.notes 
Request: Send a blank email to php-notes+get-175351@lists.php.net to get a copy of this message
To Dallas at ekkysoftware dot com: You could modify Your code to check for FALSE values that current() outputs when at the end of array, like this: <?php $row = array( 'first'=>'number', 'second'=>'letter', 'third'=>null, 'forth'=>'word'); while(($value = current($row))!==FALSE){ echo "\"".key($row)."\""; next($row); } ?> But then there would remaining the problem of what happens when there are FALSEs in the array. The correct way is, like You said, the following: <?php foreach($row as $value){ echo "\"".key($row)."\""; next($row); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 85.196.252.126 ---- Manual Page -- http://www.php.net/manual/en/function.key.php Edit -- https://master.php.net/note/edit/101626 Del: integrated -- https://master.php.net/note/delete/101626/integrated Del: useless -- https://master.php.net/note/delete/101626/useless Del: bad code -- https://master.php.net/note/delete/101626/bad+code Del: spam -- https://master.php.net/note/delete/101626/spam Del: non-english -- https://master.php.net/note/delete/101626/non-english Del: in docs -- https://master.php.net/note/delete/101626/in+docs Del: other reasons-- https://master.php.net/note/delete/101626 Reject -- https://master.php.net/note/reject/101626 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175351) next »