From 6d6555ccc919a6bb5d3981a9ddbfd8b17c37bc24 Mon Sep 17 00:00:00 2001 From: Damien Seguy Date: Wed, 29 Nov 2000 19:47:41 +0000 Subject: [PATCH] Adding details and examples to indexes behaviors. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@36739 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/array.xml | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/functions/array.xml b/functions/array.xml index bc903eb04d..0f55396bf4 100644 --- a/functions/array.xml +++ b/functions/array.xml @@ -49,6 +49,14 @@ + + Syntax "index => values", separated by commas, define index + and values. index may be of type string or numeric. When index is + omitted, a integer index is automatically generated, starting + at 0. If index is an integer, next generated index will + be the biggest integer index + 1. Note that when two identical + index are defined, the last overwrite the first. + The following example demonstrates how to create a two-dimensional array, how to specify keys for associative @@ -65,6 +73,50 @@ $fruits = array ( + + + Automatic index with <function>Array</function> + +$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13); +print_r($array); + + + which will display : + +Array +( + [0] => 1 + [1] => 1 + [2] => 1 + [3] => 13 + [4] => 1 + [8] => 1 + [9] => 19 +) + + Note that index '3' is defined twice, and keep its final value of 13. + Index 4 is defined after index 8, and next generated index (value 19) + is 9, since biggest index was 8. + + + This example creates a 1-based array. + + 1-based index with <function>Array</function> + + $firstquarter = array(1 => 'January', 'February', 'March'); + print_r($firstquarter); + + + which will display : + +Array +( + [1] => 'January' + [2] => 'February' + [3] => 'March' +) + + See also: list.