“Hapus Elemen Array PHP” Kode Jawaban

PHP menghapus item dari array

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

php hapus array item

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

unset($items[0]);

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

php lepaskan elemen dari array

$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

Hapus Elemen Array PHP

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

Hapus Elemen Array PHP

$arr1 = array(
    'geeks', // [0]
    'for', // [1]
    'geeks' // [2]
);
  
// remove item at index 1 which is 'for'
unset($arr1[1]);  
  
// Re-index the array elements
$arr2 = array_values($arr1);
  
// Print re-indexed array
var_dump($arr1);
Splendid Salmon

Hapus Elemen Array PHP

unset($user[$i]);
// Re-index the array elements
$user = array_values($user);
Splendid Salmon

Jawaban yang mirip dengan “Hapus Elemen Array PHP”

Pertanyaan yang mirip dengan “Hapus Elemen Array PHP”

Lebih banyak jawaban terkait untuk “Hapus Elemen Array PHP” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya