I have a PHP array as follows:
$messages = [312, 401, 1599, 3, ...];
I want to delete the element containing the value $del_val
If you know for definite that your array will contain only one element with that value, you can do
$key = array_search($del_val, $array);
if (false !== $key) {
unset($array[$key]);
}
If, however, your value might occur more than once in your array, you could do this
$array = array_filter($array, function($e) use ($del_val) {
return ($e !== $del_val);
});
Note: The second option only works for PHP5.3+ with Closures