使用array_slice()获取前几个值

I'd like to use an array_slice to get every value in an array iterated over, except for the current one, the one before it, and all the others until the end of the array.

So for example, say I have 5 elements:

[1, 2, 3, 4, 5]

I want a way for a condition to fire on 3, cut it out, and then also cut out 4 and 5. I have this, but I don't think it's correct:

$items = array_slice($items, $itemcount - 1);

array_slice() returns the sequence of elements from the array array as specified by the offset and length parameters.

So if you want to get the 3,4,5 your offset should be 2, because the array key ( starts from 0 ex: 0,1,2,3,4). i didn't use length in this one because i want to get it till the end (5)

$items = array_slice($items, 2);

If you want to grag 1,2 it should be like this. ( i use length 2 because i want to get the first 2 keys)

$items = array_slice($items, 0, 2);

Example