Neos\Eel\Helper\ArrayHelper::splice PHP Method

splice() public method

Allows to give multiple replacements at once:: Array.splice(array, 3, 2, 'a', 'b')
public splice ( array $array, integer $offset, integer $length = 1, mixed $replacements = null ) : array
$array array
$offset integer Index of the first element to remove
$length integer Number of elements to remove
$replacements mixed Elements to insert instead of the removed range
return array The array with removed and replaced elements
    public function splice(array $array, $offset, $length = 1, $replacements = null)
    {
        $arguments = func_get_args();
        $replacements = array_slice($arguments, 3);
        array_splice($array, $offset, $length, $replacements);
        return $array;
    }

Usage Example

 /**
  * @test
  */
 public function spliceNoReplacements()
 {
     $helper = new ArrayHelper();
     $splicedArray = $helper->splice([0, 1, 2, 3, 4, 5], 2, 2);
     $this->assertEquals([0, 1, 4, 5], $splicedArray);
 }