slice()
The slice() method returns an array with selected from start to end
Example.php
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(range(1, 10));
$arrayUtils->slice(2); // expected output: [3, 4, 5, 6, 7, 8, 9, 10]
$arrayUtils->slice(2, 4); // expected output: [3, 4]
$arrayUtils->slice(-4); // expected output: [7, 8, 9, 10]
$arrayUtils->slice(int $start = 0, int $end = null, bool $preserve_keys = false) : ArrayUtils;
$start
Zero-based index at which to start extraction.Default is0
.$end
Zero-based index at which to start extraction.Default iscount($array)
.$preserveKeys
- When set to
TRUE
keys will be preserved. Default isFALSE
which will re-index the chunk numerically
- A sliced array.
$arrayUtils->sliceAs(int $start = 0, int $end = null, bool $preserve_keys = false) : array;
ArrayUtils::sliceFrom(iterable $from, int $start = 0, int $end = null, bool $preserve_keys = false) : ArrayUtils;
ArrayUtils::sliceFromAs(iterable $from, int $start = 0, int $end = null, bool $preserve_keys = false) : array;
Last modified 2yr ago