/ Published in: PHP
I was trying to figure out the easiest way to loop through an object with PHP. Here it is.... RecursiveArrayIterator()
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$book = new stdClass();//perfunctory $book->title = "Harry Potter and the Prisoner of Azkaban"; $book->author = "J. K. Rowling"; $book->publisher = "Arthur A. Levine Books"; $book->amazon_link = "http://www.amazon.com/dp/0439136369/"; $it = new RecursiveArrayIterator($book); foreach ($it as $key=>$val) echo $key.":".$val."\n";