PHP Array Function : array_push()

The array_push() function used to insert one or more elements to the end of array. The syntax is as follows :
 array_push(array, value1, value2...);
Where array is name of the array, and value1, value2 are values to add on that arrays. Also note that the new elements which will added have always numeric keys. The function returns the new number of elements in the array.

Example :

  $my_arr = array("HTML", "CSS", "JavaScript");
  $len = count($my_arr);
  for($x = 0; $x < $len; $x++) {
    echo $my_arr[$x] . ", ";

  $len = array_push($my_arr, "PHP", "MySql", "JSP");
  echo "<br/><br/>After array_push() : <br/><br/>";

  for($x = 0; $x < $len; $x++) {
    echo $my_arr[$x] . ", ";

Output :

HTML, CSS, JavaScript,

After array_push() :

HTML, CSS, JavaScript, PHP, MySql, JSP,

Next Topic :