note 109800 deleted from control-structures.for by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Aug 2012 15:46:57 +0000 |
| Subject: | note 109800 deleted from control-structures.for by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190332@lists.php.net to get a copy of this message | ||
Note Submitter: qeremy [atta] gmail [dotta] com
----
Instead of this usage;
<?php
$arr = array("orange", "banana", "apple", "raspberry");
for ($i = 0; $i < count($arr); $i++) {
$a = $arr[$i];
echo $a ."\n";
}
// or
for ($i = 0, $c = count($arr); $i < $c; $i++) {
$a = $arr[$i];
echo $a ."\n";
}
?>
This could be more efficient;
<?php
for (; $a = $arr[1 * $i++]; ) echo $a ."\n";
?>
And sure, you have more options like foreach($arr as $a).