試試這個
<?php
$date = ['2014-04-03', '2013-04-03', '2015-04-03', '2017-04-03', '2013-09-03'];
$title = ['title1', 'title2', 'title4', 'title5', 'title6'];
$character = ['character2', 'character5', 'character1', 'character8', 'character0'];
$poster = ['poster4', 'poster1', 'poster7', 'poster9', 'poster0'];
$personArray = [
'date' => $date,
'title' => $title,
'character' => $character,
'poster' => $poster
];
/*echo "<pre>";
print_r($personArray);*/
$length_count = count($date);
$new_array = array();
for($i=0; $i<$length_count ; $i++){
$new_array[$i] = array();
foreach($personArray as $key => $value){
$new_array[$i][$key] = $personArray[$key][$i];
}
}
function date_compare($a, $b){
$t1 = strtotime($a['date']);
$t2 = strtotime($b['date']);
return $t1 - $t2;
}
usort($new_array, 'date_compare');
//print_r($new_array);
$sorted_array = array();
$sorted_array['date'] = array();
$sorted_array['title'] = array();
$sorted_array['character'] = array();
$sorted_array['poster'] = array();
foreach($new_array as $data){
array_push($sorted_array['date'], $data['date']);
array_push($sorted_array['title'], $data['title']);
array_push($sorted_array['character'], $data['character']);
array_push($sorted_array['poster'], $data['poster']);
}
//print_r($sorted_array);
?>
http://stackoverflow.com/questions/2910611/php-sort-a-multidimensional-array- by-element-containing-date –
嘗試'ksort'閱讀更多[here](http://php.net/manual/en/function.ksort.php) –
'array_multisort($ date,$ poster,$ character,$標題);' –