Reputation: 31
What am I doing wrong?
I'm trying to reverse a json_decode
using array_reverse
but I'm getting the following error
Warning: array_reverse() expects parameter 1 to be array, object given
Using the code below:
$data = file_get_contents($url);
$output = json_decode($data);
$output = array_reverse($output);
Thanks.
Upvotes: 0
Views: 408
Reputation: 1248
You have to put second parameter true
in
$output = json_decode($data, true);
by default json_decode
convert json to php-object, if you put true as parameter - it should convert it to array
Upvotes: 3