The Fastest Way to Convert Array to Object (multidimensional)
$object = (object)json_decode(json_encode($data));
$array = json_decode(json_encode($data), TRUE);
$data= array(
'base_url' => 'http://example.com/',
'uri_protocol' => 'AUTO',
'url_suffix' => '',
'language' => 'english',
'modules_locations' => array(
'core_module' => 'packages/core_modules/',
'module' => 'packages/modules/'
)
);
$convert = json_encode($data);
$object = (object)json_decode($convert);
$array = json_decode($convert, TRUE);
echo "<pre>";
print_r($object);
print_r($array);
echo "</pre>";
Written by Wahyu Kristianto
Related protips
4 Responses
What about (object) array();?
over 1 year ago
·
@robinvdvleuten (object)array();
does not support multidimensional array
over 1 year ago
·
Ah good to know, thanks
over 1 year ago
·
Is this really the "fastest" way or just the most convenient? :D
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Related Tags
#php
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#