Remove array elements : array_pop « Data Structure « PHP






Remove array elements

 
<html>
 <head>
  <title>Remove array elements</title>
 </head>
 <body>
 <ol>

 <?php
  $arr = array( "Orange", "Cherry", "Apple", "Banana", "Lemon" );

  $first = array_shift( $arr );

  $last = array_pop( $arr );

  sort( $arr );
  
  foreach( $arr as $value){ echo("$value, ");}
  echo("<br>Removed first element: $first");
  echo("<br>Removed last element: $last");
  ?>

  </ol>
 </body>
</html>
  
  








Related examples in the same category

1.array_pop( ) returns the value from the end of the array while also removing it from the array.
2.array to comma string