Your Ad Here

Posted By

sekihin on 03/26/09


Tagged

php array


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


Array Traversal


 / Published in: PHP
 

  1. $fruit = array("apple", "orage", "grape", "banana");
  2. $i=0;
  3. while (TRUE) {
  4. if (!isset($fruit[$i])) {
  5. break;
  6. }
  7. print($fruit[$i]). " \n";
  8. $i++;
  9. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: MMDeveloper on March 26, 2009

to just print the array items.. just use: echo implode("\n", $fruit);

but there's also another routine designed for this:

foreach ($fruit as $k => $v) { echo "index #" . $k . " = " . $v . "\n"; }

You need to login to post a comment.