Removing the First Element of an Array with array_shift() : array_shift « Data Structure « PHP






Removing the First Element of an Array with array_shift()

 
array_shift() removes and returns the first element of an array passed to it as an argument. 

<?php
$an_array = array("a", "b", "c");

while ( count( $an_array ) ) {
  $val = array_shift( $an_array);
  print "$val<br />";
  print "there are ".count( $an_array )." elements in \$an_array <br />";
}
?>
  
  








Related examples in the same category

1.Removing the First or Last Element from an Array
2.array_shift( ) function returns the value from the front of the array while also removing it from the array.
3.array_shift() function operates much like array_pop()