【发布时间】:2019-11-06 13:50:07
【问题描述】:
我做错了什么?
我正在尝试使用 array_reverse 反转 json_decode,但出现以下错误
警告:array_reverse() 期望参数 1 是数组,给定对象
使用下面的代码:
$data = file_get_contents($url);
$output = json_decode($data);
$output = array_reverse($output);
谢谢。
【问题讨论】:
-
您的 JSON 数据似乎由一个对象组成,而不是一个数组。简单的解决方法:设置json_decode的第二个参数为true。
-
你试过
$output = (array)json_decode($data)吗? -
json_decode($data, true);
-
$output = json_decode($data, true); prnt.sc/pt9bd0
-
也许一个更好的问题可能是你为什么需要反转数组
标签: php json array-reverse