Posted By

jferiante on 06/11/11


Tagged


Versions (?)

PHP Loop Through An Array


 / Published in: PHP
 

URL: RecursiveArrayIterator

I was trying to figure out the easiest way to loop through an object with PHP. Here it is.... RecursiveArrayIterator()

  1. $book = new stdClass();//perfunctory
  2. $book->title = "Harry Potter and the Prisoner of Azkaban";
  3. $book->author = "J. K. Rowling";
  4. $book->publisher = "Arthur A. Levine Books";
  5. $book->amazon_link = "http://www.amazon.com/dp/0439136369/";
  6.  
  7. $it = new RecursiveArrayIterator($book);
  8.  
  9. foreach ($it as $key=>$val)
  10. echo $key.":".$val."\n";

Report this snippet  

You need to login to post a comment.