Php odstranit prvek z pole

Příklady kódu

13
0

php smazat prvek podle hodnoty

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

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

php odstranit prvek z pole

//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
8
0

php odebrat pole položek

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

unset($items[0]);

var_dump($items); // ['apple']
6
0

Odstranění prvku z pole v 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
]
*/
2
0

php vymazat prvek z pole

foreach ($items as $key =>$item){
  if(condition){
    unset($item[$key]);
  }
}
1
0

php odebrat prvek z pole

$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)

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................