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 ) )
Quick hack:
Not pretty, but works.
Inspired by all these codes, i tried to create a enhanced version with support to: specific class name, avoid constructor method, 'beans' pattern and strict mode (set only existing properties):
Code
This function works as same as
json_decode(json_encode($arr), false)
.Testing
Test 1: Flat array
Output:
Test 2: Array of objects
Output:
Test 3: Object
Output:
i have done it with quite simple way,
You could also do this by adding (object) on left of variable to create a new object.
http://codepad.org/9YmD1KsU