Header PHP has a distressingly large number of functions that allow you to manipulate an array. In this post, we’ll show you how to use array_search() to delete a specific value from an array.

Code

$values = [
    1,
    42,
    12,
    88,
    99
];

$valueToRemove = 12;
$key = array_search($valueToRemove, $values);
if ($key !== false) {
    unset($values[$key]);
}

var_dump($values);

Output

array(4) {
  [0]=>
  int(1)
  [1]=>
  int(42)
  [3]=>
  int(88)
  [4]=>
  int(99)
}