[英]PHP json decode array reverse
What am I doing wrong?我究竟做错了什么?
I'm trying to reverse a json_decode
using array_reverse
but I'm getting the following error我正在尝试使用
array_reverse
json_decode
我收到以下错误
Warning: array_reverse() expects parameter 1 to be array, object given
警告:array_reverse() 期望参数 1 是数组,object 给定
Using the code below:使用下面的代码:
$data = file_get_contents($url);
$output = json_decode($data);
$output = array_reverse($output);
Thanks.谢谢。
You have to put second parameter true
in您必须将第二个参数
true
放入
$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默认情况下
json_decode
将 json 转换为 php-object,如果您将 true 作为参数 - 它应该将其转换为数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.