Skip to content

Instantly share code, notes, and snippets.

@ahmedghazi
Created August 19, 2013 10:02
Show Gist options
  • Save ahmedghazi/6267608 to your computer and use it in GitHub Desktop.
Save ahmedghazi/6267608 to your computer and use it in GitHub Desktop.
PHP stdClass: Storing Data in an Object Instead of an Array
$book = new stdClass;
$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/";
$array = array(
"title" => "Harry Potter and the Prisoner of Azkaban",
"author" => "J. K. Rowling",
"publisher" => "Arthur A. Levine Books",
"amazon_link" => "http://www.amazon.com/dp/0439136369/"
);
$books = (object) $array;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment