I have a PHP array as follows:
$messages = [312, 401, 1599, 3, ...];
I want to delete the element containing the value $del_val
The accepted answer converts the array to associative array, so, if you would like to keep it as a non-associative array with the accepted answer, you may have to use array_values too.
if(($key = array_search($del_val, $messages)) !== false) {
unset($messages[$key]);
$arr = array_values($messages);
}
The reference is here