I have an array
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
)
How can I remove
Check out array_slice()
So, if you wanted the first three elements only:
$array = array_slice($array, 0, 3);
If you wanted all but the last three elements:
$array = array_slice($array, 0, -3);
The second parameter is the start point (0 means to start from the begining of the array).
The third parameter is the length of the resulting array. From the documentation:
If
lengthis given and is positive, then the sequence will have that many elements in it. Iflengthis given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything fromoffsetup until the end of thearray.