PHP array_push() function

This function is used to push one or more elements at the end of an array.

Syntax

array_push(array, element1, element2,..);

This function returns a new array containing all old elements plus all pushed elements.

Example1

<?php
    $arr = array("car", "bus", "truck");
    array_push($arr, "cycle", "bike");
    print_r($arr);
?>		

Output :

Array ( [0] => car [1] => bus [2] => truck [3] => cycle [4] => bike )

Example2

<?php
    $arr = array();
    array_push($arr, "India", "Australia");
    print_r($arr);
?>		

Output :

Array ( [0] => India [1] => Australia )



Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_key_exists() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function




Read more articles


General Knowledge



Learn Popular Language