How to convert string as stdClass object to array [PHP]
I'm coding a login system using API. i'm stuck with the result that i got using the API. I got the result as normal string like this:
stdClass Object
(
[success] => 1
[message] => Array
(
[code] => 000
[txt] => Operation successful
)
[data] => Array
(
[result] => OK
[accountID] => 000000000
[group] => demoCAC
[currency] => USD
[enable] => 1
[read_only] => 0
[name] => Bogus Demo
[country] => ****
[city] =>
[address] =>
[phone] => **
[email] => ***@gmail.com
[status] => test
[regdate] => 07/02/2017 09:57
[lastdate] => 07/02/2017 09:57
[balance] => 0.00
[credit] => 0.00
[equity] => 10000.00
[isDemo] => 1
[tp_version] => **
[last_name] => Demo
[first_name] => Bogus
[domain] => ***.com
[compliance] =>
[latestTrades] => Array
(
[results] => Array
(
)
[totalResults] => 0
)
[owner] =>
)
)
So how can i convert it to an array or useable variable ? * This information printed by ( echo ), and i can't access $result -> data ->... is there a function that convert this string to array or json or something readable so i can reach to specific value? when i try : print_r(get_object_vars($result)); i get this error:
Warning: get_object_vars() expects parameter 1 to be object, string given in /home/**/public_html/crm/profile.php on line 20
Unless Im missing something, your problem is a simple one.
looking at the guts of your var_dump, you should be able to access the index in your question like:
$result->data['email']; // where 'email' is the key of the data.
or
$result->data['latestTrades']['results']; // nested example.
all the properties of a standard class are public, and so can be accessed directly. And in your example, all of them contain an array, or nested array so can be accessed by their key.
链接地址: http://www.djcxy.com/p/64872.html