Voting

: four plus two?
(Example: nine)

The Note You're Voting On

JumpIfBelow
8 years ago
As I see in many codes, don't use count to iterate through array.
Onlyranga says you could declare a variable to store it before the for loop.
I agree with his/her approach, using count in the test should be used ONLY if you have to count the size of the array for each loop.

You can do it in the for loop too, so you don't have to "search" where the variable is set.
e.g.
<?php
$array
= [1, 5, 'element'];
for(
$i = 0, $c = count($array); $i < $c; $i++)
var_dump($array[$i]);
?>

<< Back to user notes page

To Top