php (2次元配列の条件によるソートにおける小さな問題)
//元の配列
Array ( [1] => Array ( [date] => 2011-08-18 [num] => 5 ) [2] => Array ( [date] => 2011-08-18 [num] => 5 ) 2011-08-20 [数値] => 3 ) [3] => 配列 ( [日付] => 2011-08-17 [数値] => 10 ) )
//方法一、 $ar = Array ( 1 => Array ( 'date' => '2011-08-18', 'num' => 5 ), 2 => Array ( 'date' => '2011-08-20', 'num' => 3 ), 3 => Array ( 'date' => '2011-08-17', 'num' => 10 ) ); function mysort($a, $b) { $a = strtotime($a['date']); $b = strtotime($b['date']); if ($a == $b) return 0; return ($a < $b) ? -1 : 1; } usort($ar, 'mysort'); print_r($ar); //方法二、 $arr=array ( '1' => array ( 'date' => '2011-08-18', 'num' => 5 ) , '2' => array ( 'date' => '2011-08-20', 'num' => 3 ) , '3' => array ( 'date' => '2011-08-17', 'num' => 10 ) ) ; foreach($arr as $v){ $tmp[$v[date]]=$v; } ksort($tmp); print_r(array_values($tmp));