PhpDig.net

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




array_merge

Name

array_merge — Combines all given values into one array.

Synopsis

array array_merge(value_1, value_2[, . . .]);
mixed value_1: Base array or value
mixed value_2: Value or array to be merged with value_1
mixed . . . (optional): Further values or arrays to be merged

Returns

Array containing the results of merging all passed values; NULL on failure

Description

This function combines multiple values into a single array. Any number of values can be passed in the function call, including mixed arrays; any duplicate keys are overwritten by later elements in later arrays. Keys are merged in the order of the arrays that were passed.

Subarrays are not recursed over and are not altered; if you want to merge arrays recursively, use array_merge_recursive() .

Scalar values can also be passed; they're treated as single-element indexed arrays.

Version

PHP 4

See also

See also array_merge_recursive()

Example

Example 22. Merge arrays

$ax = array("a" => "alpha", "b" => "bravo", "c" => "charlie", "d" => "delta");
$ay = array("t" => "tango", "u" => "uniform", "v" => "victor", "w" => "whiskey", "x" => "x-ray");
$az = array("lima", "mike", "november");
echo "The merged arrays together form:\n";
print_r(array_merge($ax, $ay, $az));

Output:
The merged arrays together form:
Array
(
    [a] => alpha
    [b] => bravo
    [c] => charlie
    [d] => delta
    [t] => tango
    [u] => uniform
    [v] => victor
    [w] => whiskey
    [x] => x-ray
    [0] => lima
    [1] => mike
    [2] => november
)



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.