PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




array_push

Name

array_push — Appends the list of mixed variables onto the given array.

Synopsis

int array_push(array, vars[, . . .]);
array array: Array to which to add the new value(s)
mixed vars: Value to append to array
mixed . . . (optional): Further values to add

Returns

Description

Number of elements appended to the array; NULL on failure

This function appends one or more values to the array given by array . All values beyond the first are appended. Any type of variable can be appended, including mixed or multidimensional arrays. New elements will always have incrementally-increased numeric keys in array , and the new elements will be added in the order in which they are passed to array_push() .

This function can be used with array_pop() to treat arrays as stacks.

Warning

This function directly alters the array passed to it.

Version

PHP 4

See also

See also array_pop() , array_shift() , array_unshift()

Example

Example 28. Push values onto an array

$arr = array(10, 20, 30, 40);
$val = 50;
echo "Before: \n";
print_r($arr);
array_push($arr, $val);
echo "Pushing $val onto the array produces:\n";
print_r($arr);

Output:
Before: 
Array
(
    [0] => 10
    [1] => 20
    [2] => 30
    [3] => 40
)
Pushing 50 onto the array produces:
Array
(
    [0] => 10
    [1] => 20
    [2] => 30
    [3] => 40
    [4] => 50
)



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.