<?php echo '<pre>'; $sourceA = array( 2 => 'object 2', 3 => 'object 3', 5 => 'object 5' ); $b = array( 3 => 'new instanceof object 3', 5 => 'new instanceof object 5', 8 => 'object 8', 10 => 'object 10', 15 => 'object 15', ); /** * Print source arrays */ $a = $sourceA; // set default array echo "Sources:\n"; echo "array a:\n"; print_r($a); echo "\narray b:\n"; print_r($b); echo "\n\n"; /** * array_merge result */ echo "Results:\n"; $a = array_merge($a, $b); ksort($a); echo "1. array_merge:\n"; print_r($a); $a = $sourceA; // set default array /** * (a + b) result */ $a = $a + $b; ksort($a); echo "\n\n2. summ (a + b):\n"; print_r($a); $a = $sourceA; // set default array /** * (b + a) result */ $a = $b + $a; ksort($a); echo "\n\n3. summ (b + a):\n"; print_r($a);Sources: array a: Array ( [2] => object 2 [3] => object 3 [5] => object 5 ) array b: Array ( [3] => new instanceof object 3 [5] => new instanceof object 5 [8] => object 8 [10] => object 10 [15] => object 15 ) Results: 1. array_merge: Array ( [0] => object 2 [1] => object 3 [2] => object 5 [3] => new instanceof object 3 [4] => new instanceof object 5 [5] => object 8 [6] => object 10 [7] => object 15 ) 2. summ (a + b): Array ( [2] => object 2 [3] => object 3 [5] => object 5 [8] => object 8 [10] => object 10 [15] => object 15 ) 3. summ (b + a): Array ( [2] => object 2 [3] => new instanceof object 3 [5] => new instanceof object 5 [8] => object 8 [10] => object 10 [15] => object 15 )
Разве результат под номером 3 — это не то, что надо? Если нет, то я не понял задачу.