Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中对多维数组中的值进行排序和回显?_Php_Arrays_Function_Sorting_Multidimensional Array - Fatal编程技术网

如何在PHP中对多维数组中的值进行排序和回显?

如何在PHP中对多维数组中的值进行排序和回显?,php,arrays,function,sorting,multidimensional-array,Php,Arrays,Function,Sorting,Multidimensional Array,如何按“日期”值对该数组排序,并让ASC结果显示? 错误的格式和命名导致我的作品出现错误,从而使[“日期”]无法以ASC格式显示在表格中。 谢谢大家的帮助 数组: $arrayBooking = array( "a01"=>array( "Amy"=>array( "booking1"=>array( "231"=>array(

如何按“日期”值对该数组排序,并让ASC结果显示? 错误的格式和命名导致我的作品出现错误,从而使[“日期”]无法以ASC格式显示在表格中。 谢谢大家的帮助

数组:

$arrayBooking = array(
        "a01"=>array(
            "Amy"=>array(
                "booking1"=>array(
                    "231"=>array(
                        "date"=>"21/08/2014",
                        "period"=>array(
                            "from"=>1,
                            "to"=>3
                            )
                        )
                    )
                )
           ),
           "a02"=>array(
              "Peter"=>array(
                "booking1"=>array(
                    "231"=>array(
                        "date"=>"23/08/2014",
                        "period"=>array(
                            "from"=>2,
                            "to"=>3
                            )
                        )
                  ),
                 "booking2"=>array(
                    "231"=>array(
                        "date2"=>"20/08/2014",
                        "period"=>array(
                            "from"=>2,
                            "to"=>5
                            )
                        )
                    )
                )
            ),
            "a05"=>array(
               "Mary"=>array(
                  "booking1"=>array(
                     "321"=>array(
                        "date"=>"22/08/2014",
                            "period"=>array(
                                "from"=>3,
                                "to"=>6
                                )
                            )
                        )
                   )
              )
            )
您可以使用函数按首选算法对数组排序

usort($array, function($a, $b){
    if ($a < $b) {
       return -1;
    } elseif ($a == $b) {
       return 0;
    }
    return 1;
});

它已经按
日期排序了
它显示了几乎2%的数组信息。loli得到了它,我将尝试更新您
$stamp1 = strtotime($date1);
$stamp2 = strtotime($date2);

return $stamp1 - $stamp2;