Created
September 3, 2013 10:00
-
-
Save demaisj/6421932 to your computer and use it in GitHub Desktop.
PHP : Improved native for loop variations for much speed when iterating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | |
for($i = count($array)-1;$i >= 0; $i--) { | |
echo $array[$i].", "; | |
}; | |
/* Will produce : | |
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | |
for($i = count($array)-1;$i >= 0; $i--) { | |
$n = count($array)-1-$i; | |
echo $array[$n].", "; | |
}; | |
/* Will produce : | |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment