php unset array key
snippet in php

php delete element by value

user4835

$colors = array("blue","green","red");

//delete element in array by value "green"
if (($key = array_search("green", $colors)) !== false) {
    unset($colors[$key]);
}

php unset array key

user9505

unset($dataArray['key']);

Deleting an element from an array in PHP

user7543

$array = [0 => "a", 1 => "b", 2 => "c"];
unset($array[1]); //Key which you want to delete
/*
$array:
[
    [0] => a
    [2] => c
]
*/
//OR
$array = [0 => "a", 1 => "b", 2 => "c"];
array_splice($array, 1, 1);//Offset which you want to delet
/*
$array:
[
    [0] => a
    [1] => c
]
*/

remove key and value from array php

user7586

$arr = array('G', 'E', 'E', 'K', 'S');  
unset($arr[2]);
print_r($arr);

php unset()

user9820


<?php

  $a = "Hello world!";
echo 
  "The value of variable 'a' before unset: " . $a . "<br>";

  unset($a);
echo 
  "The value of variable 'a' after unset: " . $a;
?>