我有一个Array包含2个值的数组,第一个是作者的编号,第二个是他的隶属关系.
Array ( [0] => Array ( [0] => 2 [1] => Department of General Chemistry ) [1] => Array ( [0] => 3 [1] => Institute of Silicate Materials ) [2] => Array ( [0] => 4 [1] => Department of General Chemistry ) [3] => Array ( [0] => 5 [1] => Department of General Chemistry ) [4] => Array ( [0] => 6 [1] => Institute of Silicate Materials ) )
如果隶属关系相同,我如何分组作者?我需要输出如下:
3,6 Institute of Silicate Materials 2,4,5 Department of General Chemistry
foreach ($array as $key => $value) { $return[$value[1]][] = $value[0]; } foreach ($return as $key => $value) { echo implode(',',$value)." ".$key; }