PHP array() function

PHP array() function

The array() function in PHP is used to create an array.

Syntax

Parameter

…(optional)- This parameter represents the elements’ values along with keys of the array. The syntax of this is as follows:

“index => values” where the index represents a type string or integer. The possible index values are given below,

  • If the index is omitted, an integer index is automatically generated, starting from 0 and incremented with +1.
  • If the index is an integer, the next generated index will be the biggest integer index + 1
  • If there are two identical indexes, the last index overwrites the first.

Return

This parameter returns an array of the parameters.

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output