note 109801 added to control-structures.while
| From: | qeremy | Date: | Wed, 22 Aug 2012 08:45:10 +0000 |
| Subject: | note 109801 added to control-structures.while | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190173@lists.php.net to get a copy of this message | ||
Instead of this usage;
<?php
$arr = array("orange", "banana", "apple", "raspberry");
$i = 0;
while ($i < count($arr)) {
$a = $arr[$i];
echo $a ."\n";
$i++;
}
// or
$i = 0;
$c = count($arr);
while ($i < $c) {
$a = $arr[$i];
echo $a ."\n";
$i++;
}
?>
This could be more efficient;
<?php
while ($a = $arr[1 * $i++]) echo $a ."\n";
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.101.222.218
----
Manual Page -- http://www.php.net/manual/en/control-structures.while.php
Edit -- https://master.php.net/note/edit/109801
Del: integrated -- https://master.php.net/note/delete/109801/integrated
Del: useless -- https://master.php.net/note/delete/109801/useless
Del: bad code -- https://master.php.net/note/delete/109801/bad+code
Del: spam -- https://master.php.net/note/delete/109801/spam
Del: non-english -- https://master.php.net/note/delete/109801/non-english
Del: in docs -- https://master.php.net/note/delete/109801/in+docs
Del: other reasons-- https://master.php.net/note/delete/109801
Reject -- https://master.php.net/note/reject/109801
Search -- https://master.php.net/manage/user-notes.php