好的,所以我计划了两个阵列 - 将根据日期或时间戳进行排序,如下所示:
array([date] => "8/12/12", [rating] => 300)
并且假设第二个数组看起来像这样:
array([date] => "8/12/12", [rating2] => 600)
我想将这两者结合起来:
array([date] => "8/12/12", [rating] => 300, [rating2] => 600)
最有效的方法是什么?
答案 0 :(得分:1)
您可以在阵列上使用+
符号...
$a = array("date" => "8/12/12","rating" => 300);
$b = array("date" => "8/12/12","rating2" => 600);
var_dump($a + $b);
输出
array
'date' => string '8/12/12' (length=7)
'rating' => int 300
'rating2' => int 600
答案 1 :(得分:1)
试用array_merge
和+
运算符
$a = array( 'key' => 'abc', 'foo' => true);
$b = array( 'key' => 'abc', 'bar' => true);
print_r( $a + $b );
print_r( array_merge( $a, $b ) );