splice()
The splice() method remove a portion of the array and replace it with something else
Example.php
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(range(1, 10));
$arrayUtils->splice(2);
// expected output: [3, 4, 5, 6, 7, 8, 9, 10]
$arrayUtils;
// expected output: [1, 2]
//Reset
$arrayUtils = ArrayUtils::from(range(1, 10));
$arrayUtils->splice(2, 4, "Hi", "Bye", "Oh");
// expected output: [3, 4, 5, 6]
$arrayUtils->splice(-4);
// expected output: [1, 2, "Hi", "Bye", "Oh", 7, 8, 9]
$arrayUtils->splice(int $offset, ?int $length = null, mixed ...$replacement) : ArrayUtils;
$offset
The index at which to start changing the array.$length
Length of array to be removedDefault isNULL
. If is null, It replaced tocount($array)-$offest
.$replacement
Values to replace. If if empty, Removes elements in the selected range.
- The array consisting of the extracted elements.
$arrayUtils->spliceAs(int $offset, ?int $length = null, mixed ...$replacement) : array;
ArrayUtils::spliceFrom(iterable $from, int $offset, ?int $length = null, mixed ...$replacement) : ArrayUtils;
ArrayUtils::spliceFromAs(iterable $from, int $offset, ?int $length = null, mixed ...$replacement) : array;
Last modified 2yr ago