PHP:如何反转JSON数组

PHP:如何反转JSON数组,php,multidimensional-array,Php,Multidimensional Array,有人能帮我学点PHP吗 原始代码~正常工作,但输出顺序错误。 所以我需要颠倒JSON数组的顺序 但当我尝试使用下面的PHP(extract)代码颠倒顺序时: $json = file_get_contents($url,0,null,null); $tmp = json_decode($json, true); // using a temp variable for testing $result = array_reverse($tmp); // <--new li

有人能帮我学点PHP吗

原始代码~正常工作,但输出顺序错误。 所以我需要颠倒JSON数组的顺序

但当我尝试使用下面的PHP(extract)代码颠倒顺序时:

$json = file_get_contents($url,0,null,null); 
$tmp = json_decode($json, true);    // using a temp variable for testing
$result = array_reverse($tmp);      //  <--new line to reverse the arrray

foreach ($result['data'] as $event) {
    echo '<div>'.$event['name'].'</div>';
$json=file\u get\u contents($url,0,null,null);
$tmp=json_decode($json,true);//使用温度变量进行测试

$result=array_reverse($tmp);// 您需要反转
$tmp['data']
数组的内容,而不是
$tmp
本身

$json = file_get_contents($url); 
$tmp = json_decode($json, true);
$result = array_reverse($tmp['data']);

unset($tmp);

foreach ($result as $event) {
  echo '<div>'.$event['name'].'</div>';
}
$json=file\u get\u contents($url);
$tmp=json_decode($json,true);
$result=array_reverse($tmp['data']);
unset($tmp);
foreach($事件的结果){
回显'.$event['name'].';
}

您进行了反向操作,但在错误的字段上。要反转
数据
字段而不是数组:

$json = file_get_contents($url,0,null,null); 
$tmp = json_decode($json, true);    // using a temp variable for testing
$result = $tmp;
$result['data'] = array_reverse($result['data']);

foreach ($result['data'] as $event) {
    echo '<div>'.$event['name'].'</div>';
$json=file\u get\u contents($url,0,null,null);
$tmp=json_decode($json,true);//使用温度变量进行测试
$result=$tmp;
$result['data']=array_reverse($result['data']);
foreach($result['data']作为$event){
回显'.$event['name'].';

在我读的所有文章中,没有人能像你一样解释得那么清楚-谢谢。@hakre