Answers for "php unset array key"

PHP
15

php delete array item by value

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

//delete element in array by value "green"
if (($key = array_search("green", $colors)) !== false) {
    unset($colors[$key]);
}
Posted by: Guest on October-30-2019
5

php unset array key

unset($dataArray['key']);
Posted by: Guest on June-01-2020
6

Deleting an element from an array in PHP

$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
]
*/
Posted by: Guest on May-18-2020
0

unset by key name php

unset($array['key-here']);
Posted by: Guest on April-28-2020
1

remove key of an array php

$result_Member = $this->Member->get_list_member_belong_to_company($id);

/* 
$result_Member = array(
	[10] => 10,
    [20] => 11,
    [30] => 12,
)
*/

// remove key, get values only
$member_ids = array_values($result_Member);

/*
$result_Member = array(
	[0] => 10,
    [1] => 11,
    [2] => 12,
)
*/
Posted by: Guest on October-21-2020

Browse Popular Code Answers by Language