Lets say I have this array:
$queue = array("orange", "banana", 'apple', 'watermelon');
If I want to remove any of them,for example I want to remove banana, how to do it?
Lets say I have this array:
$queue = array("orange", "banana", 'apple', 'watermelon');
If I want to remove any of them,for example I want to remove banana, how to do it?
You'll need to search for that element and remove it using the key:
$pos = array_search('banana', $array);
if ($pos !== false) {
unset($array[$pos]);
}
If the array can contain the value more than once, you should use array_keys()
instead:
foreach (array_keys($array, 'banana') as $key) {
unset($array[$key]);
}
if (in_array('banana', $array))
{
unset($array[array_search('banana', $array)]);
}
with array_filter
:
$array = array_filter($array, create_function('$v', 'return $v != \'value to remove\';'));