2011-07-30 20 views
0

我做了這個虛構的成員列表。我想維護子數組的順序(類年),同時按每個子數組中的降序排序。如何按多維數組中的鍵排序

$pledges = array(
    'smith'  => "Joe Patterson", 
    'jones'  => "Robert Nelson", 
    'davis'  => "Jimmy Davis", 
    'carpenter' => "Mike Carpenter"); 

$sophomores = array(
    'ford'  => "Kevin Ford", 
    'gomez'  => "Pedro Gomez", 
    'miller' => "Jack Miller", 
    'pullman' => "Lucas Pullman"); 

$juniors = array(
    'bradford' => "Nicholas Bradford", 
    'daniels' => "Robert Daniels", 
    'soren'  => "Jon Soren", 
    'cooper' => "Harrison Cooper"); 

$seniors = array(
    'mcdonald' => "Casey McDonald", 
    'witten' => "Tim Witten", 
    'session' => "Benjamin Sessions", 
    'redding' => "Jack Redding"); 

我該怎麼做?謝謝一堆。

回答

0

通過使用PHP的ksort函數,您可以明智地對數組鍵進行排序。

ksort($pledges); 
array_reverse($pledges); 
and like wise for others.... 

你發佈的是單維數組,請注意ksort只適用於單維數組。