Post
Topic
Board Project Development
Re: Need help about PHP and API
by
paraboul
on 27/09/2017, 12:39:25 UTC
This is quite dumb, but if you really want to have the named variable exported to the global namespace, you can use extract()

e.g.

Code:
$data = '{"success":true,"name":"winspiral","total":196864,"withdrawn":0,"balance":196864}';
extract((array)json_decode($data), EXTR_SKIP);

echo "Hey $name, your balance is $balance";

Anyway, you shouldn't do this and avoid trashing the global namespace (or current scope), just use a regular object, like :

Code:
$obj = json_decode($data);
echo "Hey $obj->name, your balance is $obj->balance";