1$colors = array("blue","green","red");
2
3//delete element in array by value "green"
4if (($key = array_search("green", $colors)) !== false) {
5 unset($colors[$key]);
6}
1$items = ['banana', 'apple'];
2
3unset($items[0]);
4
5var_dump($items); // ['apple']
1//Delete array items with unset(no re-index) or array_splice(re-index)
2$colors = array("red","blue","green");
3unset($colors[1]);//remove second element, do not re-index array
4
5$colors = array("red","blue","green");
6array_splice($colors, 1, 1); //remove second element, re-index array
1$arr = array('a' => 1, 'b' => 2, 'c' => 3);
2unset($arr['b']);
3
4// RESULT: array('a' => 1, 'c' => 3)
5
6$arr = array(1, 2, 3);
7array_splice($arr, 1, 1);
8
9// RESULT: array(0 => 1, 1 => 3)
1$array = [0 => "a", 1 => "b", 2 => "c"];
2unset($array[1]); //Key which you want to delete
3/*
4$array:
5[
6 [0] => a
7 [2] => c
8]
9*/
10//OR
11$array = [0 => "a", 1 => "b", 2 => "c"];
12array_splice($array, 1, 1);//Offset which you want to delet
13/*
14$array:
15[
16 [0] => a
17 [1] => c
18]
19*/