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



array — Creates an array from provided values or key => value pairs.


array array([variable][, . . .]);
mixed variable (optional): Variable to place into an array element
mixed . . . (optional): Further elements


Array formed of the values or key/value pairs given as arguments


array() is a language construct used to create an array with zero or more elements. Each argument passed to the function is used as a single element for the array.

By default, the construct creates a numerically indexed array such as $array[0]. The indices start at 0 and increase by one for every element in the array. For example, this would create an array with five elements: $list = array ('alpha', 'zappa', 'bravo', 4, 2);. The first element ( 'alpha') would be stored at key 0, and the second element ('zappa') would be stored at key 1.

String indexes and specific numeric indexes can be created using the special key => value syntax when calling array() . For example, $jim = array ("birthday" => "1967/09/21", "favorite cake" => "Coconut"); would create a two-element array where the first value could be accessed via $jim['birthday'] and the second element could be accessed via $jim['favorite cake'].

array() doesn't return a special value on failure, as it will only fail on syntax errors that stop the script anyway.

Calls to array() can be nested to create multidimensional arrays.


Example 17. Basic use of array()

// Create a three-element numerically indexed array
$my_array = array("one", "two", "three");

// Create a three-element string indexed array
$assoc_array = array("a"=>"x", "b"=>"y", "c"=>"z");

// Create a mixed string and numerically indexed array
$mixed_array = array("foo"=>"bar", "COBOL","Pascal");

// Create a multidimensional array
$multi_array = array(array(1, 2, 3), array('a', 'b', 'c'));

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 The authors of this book have elected not to choose any options under the OPL. This online book was obtained from 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.