可能重複:
Sorting an associative array in PHP
Sorting a multidimensional array in PHP?排序與PHP多維數組
我有我有帶(子數組與數組排序...一些困難)類別和項目,但我無法對它們進行排序...
該陣列通常如下所示:
array
'Professional Services Applications' =>
array
'Specialized Technologies' =>
array
'Test Michiel, part 2' =>
array
0 => string '2071' (length=4)
'JAVA' =>
array
'Senior Apple Engineer' =>
array
0 => string '2067' (length=4)
'Junior Apple Engineer' =>
array
0 => string '2069' (length=4)
'Microsoft' =>
array
'Senior ECM Consultant' =>
array
0 => string '2059' (length=4)
'Junior ECM Consultant' =>
array
0 => string '2082' (length=4)
'Business Applications' =>
array
'' =>
array
'Business Analyst' =>
array
0 => string '2053' (length=4)
'Test business dingen ' =>
array
0 => string '2062' (length=4)
'acADDemICT' =>
array
'' =>
array
'Test Michiel
爲了把事情說清楚,
的類別是:專業服務應用,業務應用和acADDemICT。
的子類別是:專業,技術,JAVA和微軟 (有的沒有一個子類別!)
通過這個數組與此PHP代碼迴路我:
foreach ($job_list as $category => $subcategory) {
$page .= '<h2>' . $category .'</h2>';
foreach ($subcategory as $name => $values) {
if (!empty($name)) {
$page .= '<h3>' . $name . '</h3>';
}
foreach ($values as $vacancy => $link) {
$page .= '<li>' . l("$vacancy", "node/$link[0]") . '</li>';
}
}
}
我已經嘗試了各種不同類型的排序功能(sort()
,asort()
,ksort()
,...),但我並沒有與肺心病結束直接結果。
我的目標的一個字母順序的類別,子類別和項目...
所以,我的理想的結果應該是這樣的:
**aCCademICT:**
- Test Michiel
**Business Applications:**
- Business Analyst
- Test business
**Professional Services Applications:**
*JAVA*
- Junior Apple Engineer
- Senior Apple Enineer
*Microsoft*
- Junior ECM Consultant
- Senior ECM Consultant
*Specialize Technologies*
- Test Michiel, part 2
UPDATE:
這裏我print_r
:
Array ([Professional Services Applications] => Array ([Specialized Technologies] => Array ([Test van Michiel, part 2 ] => Array ([0] => 2071)) [JAVA] => Array ([Senior Apple Engineer ] => Array ([0] => 2067)) [Microsoft] => Array ([Junior ECM Consultant ] => Array ([0] => 2059) [Senior ECM Consultant] => Array ([0] => 2087))) [acADDemICT] => Array ([] => Array ([Test van Michiel ] => Array ([0] => 2063))) [Business Applications] => Array ([] => Array ([Business Analyst ] => Array ([0] => 2053) [Test business dingen ] => Array ([0] => 2062))))
發佈你的數組的'print_r',然後有人可以採取這一點,並在解決方案上工作。 – 2012-04-11 10:16:09
你在我的問題中看到的第一個代碼塊是我的數組的var_dump。這應該不夠嗎? – Michiel 2012-04-11 10:22:57
我只希望你的數組...不是所有關於該數組的每個元素的信息,例如類型,長度等。我可以選擇並努力尋找解決方案。而不是'var_dump',我問'print_r' – 2012-04-11 10:30:40