Share on Google+Share on Google+

php array delete element

Advertisement
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

Advertisements

Posted on: October 28, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.