PHP Array Push Array


 

PHP Array Push Array

PHP Array Push Array: This tutorial exemplifies the array_push() function. In this page we have discussed about array push array i.e. whenever we push an array into another array then the first array becomes multidimensional array.

PHP Array Push Array: This tutorial exemplifies the array_push() function. In this page we have discussed about array push array i.e. whenever we push an array into another array then the first array becomes multidimensional array.

PHP Array Push Array

In this tutorial we will study about pushing one array into another instead of pushing one element or value, to implement this we need to use array_push function. After pushing one array into another the first array becomes multi-dimensional array. Example will illustrate this point.

array_push() is one of the widely used function to add item into an array. General format, parameters it take and type of value it returns is as follows:

General Format

int array_push(array &$array, mixed $var [,mixed ..})

Parameters 

array &$array: Input array

mixed $var: Pushed value

Return Value

No of elements in the array

 

For detail please visit our web page: http://roseindia.net/tutorial/php/phpbasics/PHP-Array-Push.html

PHP Array Push Array Example 1:

<?php

$array1=array(0,1,23,45,36,8);

echo"<br/><b>Elements of the first array is :</b><br/>";

print_r($array1);

$array2=array("n","e","w","delhi");

echo"<br/><b>Elements of the second array is :</b><br/>";

print_r($array2);

array_push($array1,$array2);

echo"<br/><b>After pushing the second array into first array :</b><br/>";

print_r($array1);

?>

Output:

Elements of the first array is :
Array
(
    [0] => 0
    [1] => 1
    [2] => 23
    [3] => 45
    [4] => 36
    [5] => 8
)

Elements of the second array is :
Array
(
    [0] => n
    [1] => e
    [2] => w
    [3] => delhi
)

After pushing the second array into first array is:
Array
(
    [0] => 0
    [1] => 1
    [2] => 23
    [3] => 45
    [4] => 36
    [5] => 8
    [6] => Array
        (
            [0] => n
            [1] => e
            [2] => w
            [3] => delhi
        )

)

Ads