Home Tutorial Php Phparray php array delete element

 
 

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

Related Tags for php array delete element:


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.

Posted on: October 28, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com