php array delete element
This section demonstrates how to delete element from the given array in php
This section demonstrates how to delete element from the given array in php
- Array element can be deleted by the array_splice() function.
- array_splice removes the element starting from given index with
the given length.
- Length is optional.If not given all elements get removed
PHP Array Delete Element Example
<?php
$ar1=
array(
"aaa",
"bbb",
"ccc",
"ddd",
"eee",
"fff",
"ggg",
"hhh");
echo "<br>array
is <br>";
foreach(
$ar1 as $a){
echo " ".
$a;
}
array_splice(
$ar1,
0,
1);
echo "<br>array
after deletion is <br>";
foreach(
$ar1 as $a){
echo " ".
$a;
}
?>
Output
array is
aaa bbb ccc ddd eee fff ggg hhh
array after deletion is
bbb ccc ddd eee fff ggg hhh