Easy Tutorial
❮ Func Array Key Last Php Imageaffinematrixconcat ❯

PHP array() Function

Complete PHP Array Reference Manual

Example

Create a numerical array named $cars, assign three elements to it, and print the text containing the array values:


Definition and Usage

The array() function is used to create arrays.

In PHP, there are three types of arrays:


Syntax

Syntax for numerical arrays:

Syntax for associative arrays:

Parameter Description
key Specifies the key name (numeric or string).
value Specifies the key value.

Technical Details

Return Value: Returns an array of the parameters.
PHP Version: 4+
--- ---
Changelog: Since PHP 5.4, the short array syntax can be used, replacing array() with []. <br>For example, use $cars=["Volvo","BMW"]; instead of $cars=array("Volvo","BMW");
--- ---

More Examples

Example 1

Create an associative array named $age:

Example 2

Traverse and print the values of a numerical array:

Example 3

Traverse and print the values of an associative array:

Example 4

Create a multidimensional array:


❮ Func Array Key Last Php Imageaffinematrixconcat ❯