.我有两个数组
第一
Array ( [0] => Array ( [date] => 2012-01-10 [result] => 65 [name] => Les océans ) [1] => Array ( [date] => 2012-01-11 [result] => 75 [name] => Les mers ) [2] => Array ( [date] => 2012-01-13 [result] => 66 [name] => Les continents [type] => scores ) )
第二
Array ( [0] => Array ( [date_end] => 2012-01-12 [result] => 60 [name] => Step#1 [type] => Summary ) )
我想要这个最终结果
Array ( [0] => Array ( [date] => 2012-01-10 [result] => 65 [name] => Les océans ) [1] => Array ( [date] => 2012-01-11 [result] => 75 [name] => Les mers ) [2] => Array ( [date_end] => 2012-01-12 [result] => 60 [name] => Step#1 [type] => Summary ) [3] => Array ( [date] => 2012-01-13 [result] => 66 [name] => Les continents [type] => scores ) )
所以….我需要将我的第一个数组与第二个数组结合起来,我想按日期排序这个新数组!有人可以帮我提示我这样做吗?谢谢 !
array_merge和
usort是你的朋友.
原文链接:https://www.f2er.com/php/138184.htmlfunction cmp($a,$b){ $ad = strtotime($a['date']); $bd = strtotime($b['date']); return ($ad-$bd); } $arr = array_merge($array1,$array2); usort($arr,'cmp');