Posts tagged ‘FOR loop’

Recently I’ve learned one nice trick with for loop. When you use it, you should know he number of itereations. Most people do it like this:

  1.  
  2. $a = array(1,2,3,4,5);
  3. $s = sizeof($a);//you may use count(), but sizeof if 5% faster :)
  4. for ($i = 0; $i < $s; $i++)
  5. {
  6. //do something clever here
  7. echo $a[$i].
  8. ;
  9. }
  10.  

But this requires counting number of elements before using a loop. Continue reading ‘Nice trick with FOR loop’ »