note 96562 modified in function.key by danbrown

From: Date: Fri, 05 Mar 2010 15:22:15 +0000
Subject: note 96562 modified in function.key by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166700@lists.php.net to get a copy of this message
I had a problem when there are nulls in your data, such as:- <?php $row = array( 'first'=>'number', 'second'=>'letter', 'third'=>null, 'forth'=>'word'); while($value = current($row)){ echo "\"".key($row)."\""; next($row); } ?> The problem is that current() returns the value 'null', but it isn't the end of the list. To get the correct results I used:- <?php foreach($row as $value){ echo "\"".key($row)."\""; next($row); } ?> --was-- I had a problem when there are nulls in your data, such as:- $row = array( 'first'=>'number', 'second'=>'letter', 'third'=>null, 'forth'=>'word'); while($value = current($row)){ echo "\"".key($row)."\""; next($row); } The problem is that current() returns the value 'null', but it isn't the end of the list. To get the correct results I used:- foreach($row as $value){ echo "\"".key($row)."\""; next($row); } http://php.net/manual/en/function.key.php

« previous php.notes (#166700) next »