|
arrayCreate an array Description
array array
([ mixed
$...
] )Creates an array. Read the section on the array type for more information on what an array is. Parameters
Return ValuesReturns an array of the parameters. The parameters can be given an index with the => operator. Read the section on the array type for more information on what an array is. ExamplesThe following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays. Example #1 array example
<?php
Example #2 Automatic index with array
<?php The above example will output: 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. Example #3 1-based index with array
<?php The above example will output: Array ( [1] => January [2] => February [3] => March ) As in Perl, you can access a value from the array inside double quotes. However, with PHP you'll need to enclose your array between curly braces. Example #4 Accessing an array inside double quotes
<?php Notes
|