0

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.

Lucas Meine
  • 1,524
  • 4
  • 23
  • 32
Simon Webb
  • 31
  • 4

1 Answers1

3

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

Vasyl Zhuryk
  • 1,228
  • 10
  • 23