array_pushDescriptionNumber 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. WarningThis function directly alters the array passed to it. ExampleExample 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.
|