Это снова я.. В чём разница между $collection + $
Это снова я..
В чём разница между $collection + $_relatedObjects и array_diff_key($_relatedObjects, $collection) + $collection?
$relatedObjects = array(
2 => 'object 2',
3 => 'object 3',
5 => 'object 5'
);
$collection = array(
3 => 'new instanceof object 3',
5 => 'new instanceof object 5',
8 => 'object 8',
10 => 'object 10',
15 => 'object 15',
);
$_relatedObjects = $relatedObjects; // set default array
$_relatedObjects = $collection + $_relatedObjects;
ksort($_relatedObjects);
echo '$_relatedObjects = $collection + $_relatedObjects;' . "\n";
print_r($_relatedObjects);
echo "\n";
$_relatedObjects = $relatedObjects; // set default array
$_relatedObjects = array_diff_key($_relatedObjects, $collection) + $collection;
ksort($_relatedObjects);
echo '$_relatedObjects = array_diff_key($_relatedObjects, $collection) + $collection;' . "\n";
print_r($_relatedObjects);
$_relatedObjects = $collection + $_relatedObjects;
Array
(
[2] => object 2
[3] => new instanceof object 3
[5] => new instanceof object 5
[8] => object 8
[10] => object 10
[15] => object 15
)
$_relatedObjects = array_diff_key($_relatedObjects, $collection) + $collection;
Array
(
[2] => object 2
[3] => new instanceof object 3
[5] => new instanceof object 5
[8] => object 8
[10] => object 10
[15] => object 15
)
Я правду не понимаю :-(
Ну а вообще, здорово, конечно, что так оперативно)