<?php
$arr=[10,20,30,40,50,60]
echo var_export(array_slice($arr,offset :2,length:-2)
The -2 here is to delete the last two elements of the return value. Why can't the length be written directly as 2? Is there a difference between the two?
length
Optional. numerical value. Specifies the length of the returned array.
If the value is set to an integer, this number of elements is returned.
If this value is set to a negative number, the function will terminate fetching this far from the end of the example array.
If this value is not set, all elements starting from the position set by the start parameter to the end of the array are returned.
length
Optional. numerical value. Specifies the length of the returned array.
If the value is set to an integer, this number of elements is returned.
If this value is set to a negative number, the function will terminate fetching this far from the end of the example array.
If this value is not set, all elements starting from the position set by the start parameter to the end of the array are returned.