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$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*/
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)
1foreach ($items as $key =>$item){
2 if(condition){
3 unset($item[$key]);
4 }
5}
1//NO KEY supplied
2$message array("a", "b", "c", "d");
3$del_val = "b";
4if (($key = array_search($del_val, $messages)) !== false) {
5 unset($messages[$key]);
6}