How can i convert an array like this to object?
[128] => Array ( [status] => Figure A. Facebook's horizontal scrollbars showing up on a 1024x768 screen resolution. ) [129] => Array ( [status] => The other day at work, I had some spare time ) )
How can i convert an array like this to object?
[128] => Array ( [status] => Figure A. Facebook's horizontal scrollbars showing up on a 1024x768 screen resolution. ) [129] => Array ( [status] => The other day at work, I had some spare time ) )
CakePHP has a recursive Set::map class that basically maps an array into an object. You may need to change what the array looks like in order to make the object look the way you want it.
http://api.cakephp.org/view_source/set/#line-158
Worst case, you may be able to get a few ideas from this function.
Easy:
Example:
Then, the following is true:
This one worked for me
usage :
returns :
like usual you can loop it like:
I would definitly go with a clean way like this :
if you submit:
you will get this:
I found this more logical comparing the above answers from Objects should be used for the purpose they've been made for (encapsulated cute little objects).
Also using get_object_vars ensure that no extra attributes are created in the manipulated Object (you don't want a car having a family name, nor a person behaving 4 wheels).
You could also use an ArrayObject, for example:
Its way to simple, This will create an object for recursive arrays as well: