note 36488 added to function.next
| From: | m dot schot at sockit dot nl | Date: | Sat, 11 Oct 2003 11:32:20 +0000 |
| Subject: | note 36488 added to function.next | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58238@lists.php.net to get a copy of this message | ||
When using next($var) on an array containing an empty string or 0, next will stop at that item.
$var=array("a"=>"aaaa","b"=>"","c"=>"cccc");
reset($var);
do{
echo current($var)."\n";
}while(next($var));
this should print:
aaaa
cccc
but it prints:
aaaa
The null value is not printed and the loop is stopped.
When you loop over it with:
for($counter=0;$counter<count($var);$counter++){
echo current($var)."\n";
next($var);
}
The output will be as it should be so my guess is that next returns false on null values. Foreach
does it correctly as well.
----
Manual Page -- http://www.php.net/manual/en/function.next.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36488
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36488&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36488&report=yes
Search -- http://master.php.net/manage/user-notes.php