array_push() function in PHP


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
)

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Dec-2019

82 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements