array

PHP 4, PHP 5, PHP 7, PHP 8
array - Create an array
Array Online Tool
Manual
Code Examples

Example #1 1-based index with array

This example creates a 1-based array.
Result: Array ( [1] => January [2] => February [3] => March )
PHP Version:

Example #2 Automatic index with array

Result: Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 13 [4] => 1 [8] => 1 [9] => 19 )
PHP Version:

Example #3 Accessing an array inside double quotes

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.

PHP Version:

Example #4 array example

The 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.

PHP Version: