array
An array in PHP is actually an ordered map.
Specifying with array()
An array can be created using the array() language construct.
The comma after the last array element is optional and can be omitted.
Syntax
array(
key => value,
key2 => value2,
key3 => value3,
...
)
Short array syntax
Key casts
- Strings containing valid decimal integers, unless the number is preceded by a + sign, will be cast to the integer type .
- Floats are also cast to integers, which means that the fractional part will be truncated.
- Bools are cast to integers, too, i.e. the key true will actually be stored under 1 and the key false under 0.
- Null will be cast to the empty string, i.e. the key null will actually be stored under "".
- Arrays and objects can not be used as keys.
Related concepts
→
array
→
- iterable
- array|object
- Variable parsing: Simple syntax
- Variable parsing: Complex (curly) syntax
- String: String access and modification by character
- String: Converting to string
- array: Specifying with array()
- array: Short array syntax
- array: Key casts
- Variables in PHP
- Predefined Variables
- iterable: Iterable Type Variance
- object: Converting to object
- callback: Passing