note 106803 deleted from function.array-merge by googleguy
| From: | googleguy@php.net | Date: | Sat, 12 Jan 2013 11:04:00 +0000 |
| Subject: | note 106803 deleted from function.array-merge by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192983@lists.php.net to get a copy of this message | ||
Note Submitter: ventzy dot public at gmail dot com
----
On line to merge arrays WITHOUT REINDEXING numerical keys and WITH OVERWRITING:
$result = array_diff_key($a, $b) + $b
<?php
// example
$array1 = array(0 => 'zero_a', 2 => 'two_a', 3 => 'three_a');
$array2 = array(1 => 'one_b', 3 => 'three_b', 4 => 'four_b');
$result = array_diff_key($array1, $array2) + $array2;
//$result = array(
// 0 => 'zero_a'
// 2 => 'two_a'
// 1 => 'one_b'
// 3 => 'three_b'
// 4 => 'four_b')
?>