It's really important to check the return value is not false! I used array_search() to determine the index of an value to unset this value and then realized that $arr[false] === $arr[0] !
<?php
$arr = ['apple', 'banana'];
var_dump($arr[0] === 'apple'); // true
var_dump($arr[false] === $arr[0]); // true
var_dump($arr[false] === 'apple'); // true
unset($arr[array_search('banana', $arr)]); //index = 1
var_dump($arr);
// result
// array(1) {
// [0]=>
// string(5) "apple"
// }
unset($arr[array_search('peach', $arr)]); //not found, result is false
var_dump($arr);
// result
// array(0) {
// }
// because $arr[false] === $arr[0]
?>
So always check the return of array_search!