<?php
$prvi = [
'jabolka' => 'Jabolka',
'hruske' => 'Hruške'
];
$drugi = [
'borovnice' => 'Borovnice',
'pomarance' => 'Pomaranče'
];
array_splice_preserve_keys( $prvi, 1, null, $drugi );
echo '<pre>'.print_r($prvi, true).'</pre>';
function array_splice_preserve_keys(&$input, $offset, $length=null, $replacement=array()) {
if (empty($replacement)) {
return array_splice($input, $offset, $length);
}
$part_before = array_slice($input, 0, $offset, $preserve_keys=true);
$part_removed = array_slice($input, $offset, $length, $preserve_keys=true);
$part_after = array_slice($input, $offset+$length, null, $preserve_keys=true);
$input = $part_before + $replacement + $part_after;
return $part_removed;
}
preferences:
48.45 ms | 402 KiB | 5 Q