I have some JSON like this:
{"100":{"id":100,"name":"example"},"200":{"id":200,"name":"example2"}}
Which I converted to an array:
[100] => Array
(
[id] => 100
[name] => "example"
)
[200] => Array
(
[id] => 200
[name] => "example"
)
I want to return a random [id] - or a random array name because they are the same as the IDs. How can I do this?
I've tried:
$src = "http://domain.com/json.json";
$data = file_get_contents($src);
$obj = json_decode($data, true);
$rand = array_rand($obj);
echo strval($obj[$rand]);
Which outputs:
Notice: Array to string conversion in C:/Users/Will/Documents/PHP/TestJson.php on line 7
Array
I want it to either output 100 or 200.