PHP's array_splice() function helps to replace or extract array elements for particular offset. It accepts the array, offset, optionally length and replacement array if to be replaced. It returns the array consisting of the extracted elements.
PHP's array_splice()
function helps to replace or extract array elements for particular offset. It accepts the array, offset, optionally length and replacement array if to be replaced. It returns the array consisting of the extracted elements.
array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = FALSE ]] )
Example:
$input = array("a", "b", "c", "d", "e");
var_dump(array_slice($input, 2));
var_dump(array_slice($input, -2, 1));
var_dump(array_slice($input, 0, 3));
Result:
Array
(
[0] => c
[1] => d
[2] => e
)
Array
(
[0] => d
)
Array
(
[0] => a
[1] => b
[2] => c
)