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.
remove 1 value from array
Moderator: General Moderators
may want to look in these links :
http://www.php.net/array
http://www.php.net/manual/en/function.array-slice.php
http://www.php.net/array
http://www.php.net/manual/en/function.array-slice.php
-
niceguyeddie
- Forum Newbie
- Posts: 13
- Joined: Fri Nov 28, 2003 7:12 am
- Location: Westminster, MD
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);
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);