Array (
[0] => Array (
[c_id] => 1
[semester] => 1
[level] => 100
[code] => ges 101
[title] => english language
[units] => 3
[lecturer] => aboh
[department] => philosophy
[matric] => 487
[session] => 2011/2012
)
[1] => Array (
[c_id] => 2
[semester] => 1
[level] => 100
[code] => phi 102
[title] => aristotelian logic
[units] => 3
[lecturer] => offor
[department] => philosophy
[matric] => 487
[session] => 2011/2012
)
[2] => Array (
[c_id] => 3
[semester] => 1
[level] => 100
[code] => ges 102
[title] => methodology
[units] => 3
[lecturer] => akunne
[department] => philosophy
[matric] => 487
[session] => 2011/2012
)
[16] => Array (
[c_id] => 28
[semester] => 1
[level] => 200
[code] => phi 209
[title] => introduction to epistemology
[units] => 3
[lecturer] => akunne
[department] => philosophy
[matric] => 487
[session] => 2011/2012
)
[17] => Array (
[c_id] => 29
[semester] => 1
[level] => 200
[code] => phi 207
[title] => philosophy of mind
[units] => 3
[lecturer] => akoleowo
[department] => philosophy
[matric] => 487
[session] => 2011/2012
)
[18] => Array (
[c_id] => 30
[semester] => 1
[level] => 200
[code] => rcs 211
[title] => introduction to old testament
[units] => 2
[lecturer] => acha
[department] => philosophy
[matric] => 487
[session] => 2011/2012
)
[19] => Array (
[c_id] => 31
[semester] => 1
[level] => 200
[code] => phi 204
[title] => philosophy of nature
[units] => 3
[lecturer] => mbukanma
[department] => philosophy
[matric] => 487
[session] => 2011/2012
)
我希望将数组组合在一起,使公共值成为一个关键,例如将100作为一个键,并在其所属的特定层中获取数组的所有值。
答案 0 :(得分:0)
试试这个:
$array = ... //your array
$groupedArray = array();
foreach ($array as $item) {
$groupedArray[$item['level']][] = $item;
}
这就是你想要的吗?