I'm trying to sort a array of this kind :
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 need to sort t开发者_如何学Gohis array on this key : array[$i]['debut'] on an ascending order.
The results must be :
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,
),
));
Have you an idea to do it ?
You need to use uasort
to write a function that will sort the array for you.
http://php.net/manual/en/function.uasort.php
Basically you write your own comparison function and pass it as a callback to the uasort
method
精彩评论