PHP Array push


 

PHP Array push

This section demonstrates the use of array_push function in php

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

 

Ads