Share on Google+Share on Google+

PHP Array push

Advertisement
This section demonstrates the use of array_push function in php

  • Element in the array is pushed or added at its end.
  • This is done by the function array_push().
  • array_push function adds Single or multiple elements


PHP Array Push Function Example

<?php
    $arr1
=array(1,2,3,4,5);
    foreach
($arr1 as $ar) {
      echo
" ".$ar;
     }
 
    echo
"<br>after pushing elements <br>";
    array_push($arr1,12,19);

    foreach
($arr1 as $ar1){
     echo
" ".$ar1;
     }
?>

Output
1 2 3 4 5
after pushing elements
1 2 3 4 5 12 19

 

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.