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_Algorithm_Multidimensional Array - Fatal编程技术网

Php 如何按日期对该数组进行排序?

Php 如何按日期对该数组进行排序?,php,arrays,algorithm,multidimensional-array,Php,Arrays,Algorithm,Multidimensional Array,我正在尝试对此类数组进行排序: array ( 0 => array ( 'id_ouverture' => 5, 'debut' => '2011-04-25 08:00:00', 'fin' => '2011-04-25 20:00:00', 'id_salle' => array( 'id' => '7', 'nom' => 'BLABLA', 'id_t

我正在尝试对此类数组进行排序:

array (
  0 => 
  array (
    'id_ouverture' => 5,
    'debut' => '2011-04-25 08:00:00',
    'fin' => '2011-04-25 20:00:00',
    'id_salle' => 
    array(
       'id' => '7',
       'nom' => 'BLABLA',
       'id_type_salle' => '3',
       'visible' => 1,          
    ),
  ),
  1 => 
  array (
    'id_ouverture' => 6,
    'debut' => '2011-04-18 08:00:00',
    'fin' => '2011-04-18 10:45:00',
    'id_salle' => 
    array(
       'id' => '7',
       'nom' => 'BLABLA',
       'id_type_salle' => '3',
       'visible' => 1,           
    ),
  ),
  2 => 
  array (
    'id_ouverture' => 7,
    'debut' => '2011-05-02 08:00:00',
    'fin' => '2011-05-02 10:45:00',
    'id_salle' => 
    array(
       'id' => '7',
       'nom' => 'BLABLA',
       'id_type_salle' => '3',
       'visible' => 1,
    ),
  ),
  3 => 
  array (
    'id_ouverture' => 8,
    'debut' => '2011-05-09 08:00:00',
    'fin' => '2011-05-09 10:45:00',
    'id_salle' => 
    array(
       'id' => '7',
       'nom' => 'BLABLA',
       'id_type_salle' => '3',
       'visible' => 1,           
    ),
  ));
我需要按照这个键对这个数组进行排序:数组[$I]['defestment']按升序排列

结果必须是:

array (
  1 => 
  array (
    'id_ouverture' => 6,
    'debut' => '2011-04-18 08:00:00',
    'fin' => '2011-04-18 10:45:00',
    'id_salle' => 
    array(
       'id' => '7',
       'nom' => 'BLABLA',
       'id_type_salle' => '3',
       'visible' => 1,           
    ),
  ),
  0 => 
  array (
    'id_ouverture' => 5,
    'debut' => '2011-04-25 08:00:00',
    'fin' => '2011-04-25 20:00:00',
    'id_salle' => 
    array(
       'id' => '7',
       'nom' => 'BLABLA',
       'id_type_salle' => '3',
       'visible' => 1,          
    ),
  ),

  2 => 
  array (
    'id_ouverture' => 7,
    'debut' => '2011-05-02 08:00:00',
    'fin' => '2011-05-02 10:45:00',
    'id_salle' => 
    array(
       'id' => '7',
       'nom' => 'BLABLA',
       'id_type_salle' => '3',
       'visible' => 1,
    ),
  ),
  3 => 
  array (
    'id_ouverture' => 8,
    'debut' => '2011-05-09 08:00:00',
    'fin' => '2011-05-09 10:45:00',
    'id_salle' => 
    array(
       'id' => '7',
       'nom' => 'BLABLA',
       'id_type_salle' => '3',
       'visible' => 1,           
    ),
  ));

您有什么想法吗?

您需要使用
uasort
编写一个函数来为数组排序

基本上,您可以编写自己的比较函数,并将其作为回调传递给
uasort
方法