2011-04-14 8 views
0

私は、この種の配列をソートしようとしている:昇順に配列[$ i]と[「デビュー」]:この配列を日付で並べ替えるにはどうすればいいですか?

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,   
    ), 
)); 

が、私はこのキーで、この配列をソートする必要があります。

結果がでなければなりません:

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,   
    ), 
)); 

はあなたにそれを行うためのアイデアをお持ちですか?

答えて

2

配列をソートする関数を書くには、uasortを使用する必要があります。

http://php.net/manual/en/function.uasort.php

基本的にあなたがあなた自身の比較関数を記述し、uasort方法

へのコールバックとして渡します