在一個PHP中我有一個這樣的數組。在二維數組中按鍵排序數組
$task_array = array(
'0' => array('task_name' => 'tsk3','task_chapter_name' => 'chapter3'),
'1' => array('task_name' => 'tsk1','task_chapter_name' => 'chapter1'),
'2' => array('task_name' => 'tsk2','task_chapter_name' => 'chapter2'),
'3' => array('task_name' => 'tsk6','task_chapter_name' => 'chapter6'),
'4' => array('task_name' => 'tsk4','task_chapter_name' => 'chapter3'),
'5' => array('task_name' => 'tsk6','task_chapter_name' => 'chapter4'),
'6' => array('task_name' => 'tsk6','task_chapter_name' => 'chapter7')
);
我想要做的是task_chapter_name
但一個條件排序是有,如果task_chapter_name
值相同,則下一個排序應該task_name
明智的。
所需的輸出
$task_array = array(
'0' => array('task_name' => 'tsk1','task_chapter_name' => 'chapter1'),
'1' => array('task_name' => 'tsk2','task_chapter_name' => 'chapter2'),
'2' => array('task_name' => 'tsk3','task_chapter_name' => 'chapter3'),
'3' => array('task_name' => 'tsk4','task_chapter_name' => 'chapter3'),
'4' => array('task_name' => 'tsk6','task_chapter_name' => 'chapter4'),
'5' => array('task_name' => 'tsk6','task_chapter_name' => 'chapter6'),
'6' => array('task_name' => 'tsk6','task_chapter_name' => 'chapter7')
);
我的問題被標記爲複製,但在這裏,我想告訴你,我有優先與多維數組排序,我的首要任務是通過task_chapter_name
現在如果我要進行排序在task_chapter_name
獲得相同的值,那麼它應該排序task_name
。
難道在這之前...死守。 – Aaron
好的。 。 waittting ,. , –
http://stackoverflow.com/a/3233009/3355243 – Linesofcode