“PHP Usuń element tablicy” Kod odpowiedzi

PHP Usuń element tablicy według wartości

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

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

PHP Usuń element z tablicy

if (in_array('strawberry', $array)) 
{
    unset($array[array_search('strawberry',$array)]);
}
Weary Wildebeest

PHP Usuń tablicę elementów

$items = ['banana', 'apple'];

unset($items[0]);

var_dump($items); // ['apple']
alexisgeneau

PHP Usuń element z tablicy

$arr = array('a' => 1, 'b' => 2, 'c' => 3);
unset($arr['b']);

// RESULT: array('a' => 1, 'c' => 3)

$arr = array(1, 2, 3);
array_splice($arr, 1, 1);

// RESULT: array(0 => 1, 1 => 3)
Mobile Star

PHP Usuń element tablicy

//Delete array items with unset(no re-index) or array_splice(re-index)
$colors = array("red","blue","green");                             
unset($colors[1]);//remove second element, do not re-index array

$colors = array("red","blue","green");
array_splice($colors, 1, 1); //remove second element, re-index array
Grepper

Usuwanie elementu z tablicy w 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
]
*/
Matteoweb

Odpowiedzi podobne do “PHP Usuń element tablicy”

Pytania podobne do “PHP Usuń element tablicy”

Więcej pokrewnych odpowiedzi na “PHP Usuń element tablicy” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu