Page 1 of 1

remove 1 value from array

Posted: Sun Dec 21, 2003 10:58 pm
by fxchain
Imagine this array:

Array
(
[0] => orange
[1] => banana
[2] => apple
[3] => raspberry
)


Is there an easy way to remove the banana value so it looks like this:

Array
(
[0] => orange
[1] => apple
[2] => raspberry
)

Thank you for any help.

Posted: Sun Dec 21, 2003 11:07 pm
by infolock

Posted: Mon Dec 22, 2003 5:47 am
by niceguyeddie
http://www.php.net/manual/en/function.array-pop.php

Will also work, if you reorder the array.

Posted: Mon Dec 22, 2003 10:32 am
by Scribbler
I believe that's a job for array_splice() not array_slice().

array_splice(array data, integer start, integer stop, array insert_data)


If you leave insert_data out, then it removes the array items without replacing them with the new data. If integer stop is a negative number, then it'll reference from the end of the array backward. If stop is positive, but less than start, then it'll insert items at integer_start without removing any.

So to remove the banana you'd use

array_splice($myArray, 1, 1);