array_push() function in php || array push function in php
×


array_push() function in php

2330

array_push() function of PHP is used to insert one or more item to the end of an array. It is an inbuilt function of PHP.

Syntax:

array_push($arr,$value1,$value2,.....,$valueN);

Here

$arr is a PHP array and $value1,$value2 and $valueN are values to be added to the end of $arr.


Example:

<?php
$arr1 = array("fruit1"=>"apple","fruit2"=>"banana","fruit3"=>"orange");
echo "<pre>";
echo "Before apply array_push() function <br>";
print_r($arr1);
array_push($arr1,"grape","pear");
echo "<br> After apply array_push() function";
print_r($arr1);
?>

Output:




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments