O'Reilly logo

PHP Quick Scripting Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 5

image

Arrays

An array is used to store a collection of values in a single variable. Arrays in PHP consist of key-value pairs. The key can either be an integer (numeric array), a string (associative array) or a combination of both (mixed array). The value can be any data type.

Numeric arrays

Numeric arrays store each element in the array with a numeric index. An array is created using the array constructor. This constructor takes a list of values which are assigned to elements of the array.

$a = array(1,2,3);

As of PHP 5.4 a shorter syntax is available, where the array constructor is replaced with square brackets.

$a = [1,2,3];

Once the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required