合并兩個二維陣列後依 name 欄位排序。
$aA=array(array('id'=>'7','bid'=>'7','name'=>'bbb'), array('id'=>'4','bid'=>'5','name'=>'ddd'), array('id'=>'6','bid'=>'3','name'=>'fff')); $aB=array(array('id'=>'1','name'=>'aaa'), array('id'=>'3','name'=>'ccc'), array('id'=>'5','name'=>'eee')); $aC=array_merge($aA,$aB); //合并 function cmb($a,$b){ if ($a['name'] == $b['name']) { return 0; } return ($a['name'] > $b['name']) ? -1 : 1; } usort($aC, "cmb"); //排序 foreach ($aC as $k => $v) { echo "$k <br>"; foreach ($v as $key => $value) { echo "$key: $value <br>"; } }