How many types of arrays are available in PHP?
There are three types of arrays in PHP.
| Type | Keys | Example |
|---|---|---|
| Indexed array | Numbers, from 0 | ["Apple", "Banana"] |
| Associative array | Names that you choose | ["name" => "Robin", "age" => 25] |
| Multidimensional array | An array inside an array | [[1, 2], [3, 4]] |
<?php
$indexed = ["Apple", "Banana"];
$assoc = ["name" => "Robin", "age" => 25];
$multi = [[1, 2], [3, 4]];
echo $indexed[1] . "<br>";
echo $assoc["name"] . "<br>";
echo $multi[1][0];
?>
Output:
Tutorials Class - Output Window
Banana
Robin
3
Learn all of them with examples in PHP Arrays.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |