Content health: prewriting stage
This chapter is not yet finished. To speed up the progress, help us fix it at GitHub.

Arrays

Array is a container with a fixed number of elements, where each element is indexed from 0 incrementally:

<?php

$planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'];

// Outputs "Earth"
echo $planets[2];

Associative arrays:

<?php

$array = [
    'foo' => 'bar',
    'bar' => 'foo',
];

// Outputs "bar"
echo $array['foo'];

Operations on arrays

Operator Name Result
$a + $b Union Union of $a and $b.
$a == $b Equality TRUE if $a and $b have the same key/value pairs.
$a === $b Identity TRUE if $a and $b have the same key/value pairs in the same order and of the same types.
$a != $b Inequality TRUE if $a is not equal to $b.
$a <> $b Inequality TRUE if $a is not equal to $b.
$a !== $b Non-identity TRUE if $a is not identical to $b.


Found a typo? Something wrong with this content?

Just fork and edit it.

Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all contributors.