将两个数组合并为replcaing值

时间:2016-09-01 01:30:24

标签: php arrays

我有两个阵列。

$mainarray = array( 123456 => array("id" => 123456,"data_reference_id" => 456788,"event_type_id" => 162,"event_handle" => 'Work Order #456788 Outgoing Email to <strong>Mr Maan</strong> by <strong>System</strong>',"updated_by"=> 801) );


$emailarray = array( 123456 => array("id" => 123456,"data_reference_id" => 456788,"event_type_id" => 162,"event_handle" => 'Work Order #456788 Outgoing Email to <strong>1 resident</strong> by <strong>System</strong>',"updated_by" =>'') );

如果我使用array_merge,只需将$emailarray附加到$mainarray

$finalarray = array_merge( $emailarray, $mainarray );

如果我使用+运算符,它会给出第一个数组(左数组到+运算符)。

预期结果应为

$finalarray = array( 123456 => array("id" => 123456,"data_reference_id" => 456788,"event_type_id" => 162,"event_handle" => 'Work Order #456788 Outgoing Email to <strong>1 resident</strong> by <strong>System</strong>',"updated_by"=> 801) );

有没有办法得到这个?

2 个答案:

答案 0 :(得分:0)

这可能会给你一些你想要的东西:

$finalarray =  array_unique(array_merge($mainarray,$emailarray));

答案 1 :(得分:0)

以这种方式测试它会帮助您获得预期的结果,用于array_unique

$finalarray = array_unique(array_merge($mainarray,$emailarray), SORT_NUMERIC );
echo '<pre>';
print_r($finalarray);
echo '</pre>';