Posted By

priteshloke on 01/16/11


Tagged

array


Versions (?)

Iterate enumerative and associate array using for loop


 / Published in: PHP
 

  1. $list = array(2 => 'Pritesh' , 3 => 'Sumit', 4 => 'Mehul', 'max' => 'pain');
  2. iterate_array_with_for($list);
  3. function iterate_array_with_for($list)
  4. {
  5. $list_count = count($list);
  6. if ($list_count > 0)
  7. {
  8. reset($list);
  9. for ($i = 0; $i < $list_count; $i++, next($list))
  10. {
  11. $value = current($list);
  12. $key = key($list);
  13. print "key $key and value $value <br />";
  14. }
  15. }
  16. }

Report this snippet  

You need to login to post a comment.