繁体   English   中英

PHP json 解码阵列反向

[英]PHP json decode array reverse

我究竟做错了什么?

我正在尝试使用array_reverse json_decode我收到以下错误

警告:array_reverse() 期望参数 1 是数组,object 给定

使用下面的代码:

$data = file_get_contents($url);

$output = json_decode($data);

$output = array_reverse($output);

谢谢。

您必须将第二个参数true放入

$output = json_decode($data, true);

默认情况下json_decode将 json 转换为 php-object,如果您将 true 作为参数 - 它应该将其转换为数组

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM