array_push() function in PHP

PHPProgrammingServer Side Programming

The array_push() function inserts one or more elements to the end of an array. It returns the new elements pushed into the array.

Syntax

array_push(arr, val1, val2)

Parameters

  • arr − The specified array
  • val1 − The value to be pushed
  • val2 − The value to be pushed

Return

The array_push() function returns the new elements pushed into the array.

Example

The following is an example −

 Live Demo

<?php
$arr = array("table", "chair","pen", "pencil");
array_push($arr,"notepad", "paperclip");
print_r($arr);
?>

Output

The following is the output −

Array
(
[0] => table
[1] => chair
[2] => pen
[3] => pencil
[4] => notepad
[5] => paperclip
)
raja
Published on 15-Oct-2018 12:17:43
Advertisements