Home Tutorial Php Phparray php array delete element

 
 

php array delete element
Posted on: October 28, 2009 at 12:00 AM
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

Related Tags for php array delete element:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.