I have an array:
$array = [1,2,3,4,5,6,7,8];
How do I select a subset of the array, to return just [2,3,4,5,6]?
I think it should be something along the lines of:
$array[2-6]
but that's not working
You want to use array_slice($array, 1, 5)
http://php.net/manual/en/function.array-slice.php
Use array_slice():
$array = [1,2,3,4,5,6,7,8];
$output = array_slice($array, 1, 5);
print_r($output);
Output:
Array
(
[0] => 2
[1] => 3
[2] => 4
[3] => 5
[4] => 6
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With