PHP Loop Through An Array


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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";

URL: RecursiveArrayIterator

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.