About
I'm Nobu, a web developer living in Mountain View, CA. Feel free to comment on any posts. I'm also tweeting on twitter.
Archives
-
add-on amazon rds applescript cocoa css firefox gmail javascript jquery mac mamp mashup mongo mysql oauth Open Tab-History In New Tab pear php skype social SweetCatcher twitter vim
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.
-
Recent Posts
-
Blog under the Creative Commons Attribution 3.0 License
This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.
Convert multiple object to array in PHP
For simple object, just use cast syntax should be fine.
However, this way doesn’t work for complexed object (or array+object combination) like this:
array(2) { [0]=> object(stdClass)#1 (1) { ["id"]=> int(0) } [1]=> object(stdClass)#2 (1) { ["id"]=> int(1) } }Then, simply this one liner works well.
Since I’m getting use more json_decode(), I get “PHP Fatal error: Cannot use object of type stdClass as array” sometimes. Actually in this context, to use the second parameter of json_decode is the simplest way.