Adding an Element to the End of an Array : array_push « Data Structure « PHP






Adding an Element to the End of an Array

 
<?php
  $languages = array();
  
  $languages[] = 'German';
  $languages[] = 'French';
  $languages[] = 'Spanish';
  
  printf("<p>Languages: %s.</p>\n", implode(', ', $languages));
?>

<?php

  $languages = array();

  array_push($languages, 'German', 'French', 'Spanish');

  printf("<p>Languages: %s.</p>\n", implode(', ', $languages));
?>
  
  








Related examples in the same category

1.Adding array elements
2.array_push( ) pushes value onto the end of the array
3.array_push() function appends one or more values onto the end of the array.
4.Push one or more elements onto the beginning of array
5.Push one or more elements onto the end of array