<?php
$input = array(
'a' => 'b',
'c' => 'd',
'e' => 'f',
'g' => 'h',
'i' => 'j',
'k' => 'l',
);
$replacement = array(
'w' => 'x',
'y' => 'z'
);
$offset = -3; // illegal offset - MAGIC?
$length = 2;
if ($replacement === null) {
// + operator with null causes FATAL ERROR!
$replacement = array();
}
if (empty($input)) {
$input = $replacement;
return;
}
// split array at $offset and prevent keys (4th argument)
$beforeItems = array_slice($input, 0, $offset, true);
$afterItems = array_slice($input, $offset, null, true);
if ($length !== null) {
$length = (int)$length;
// remove items
while ($length > 0) {
array_shift($afterItems);
$length--;
}
}
$input = $beforeItems + $replacement + $afterItems;
print_r($input);
preferences:
42.52 ms | 402 KiB | 5 Q