Well, you yourself have come up with it, using two cycles:
for($j=$arr[0];$j<$arr[4];$j++){
$j goes from $arr[0] , which is equal to one, to $arr[3] - fours. In other words, the following loop is executed:
for ($j = 1; $j < 5; $j++) { echo $arr[$j]; }
since the array starts with the zero element, it is output from the second to the fifth.
Of course, you really only need one cycle.
function arraySliceImplementation($array, $start, $length) { $length = ($start + $length) < sizeof($array) ? $length : sizeof($array) - $start; $copy = []; for ($i = $start; $i < $start + $length; $i++) { $copy[] = $array[$i]; } return $array; }
(maybe somewhere wrong with the array boundaries, I always have a bad time with this)