Arrays
If you have some experience with other programming languages or data structures in general, you might be aware of two data structures that are very common and useful: lists and maps. A list is an ordered set of elements, whereas a map is a set of elements identified by keys. Let's see an example:
List: ["Harry", "Ron", "Hermione"] Map: { "name": "James Potter", "status": "dead" }
The first element is a list of names that contains three values: Harry
, Ron
, and Hermione
. The second one is a map, and it defines two values: James Potter
and dead
. Each of these two values is identified with a key: name
and status
respectively.
In PHP, we do not have lists and maps; we have arrays. An array is a data structure that implements both, a list and a ...
Get Learning PHP 7 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.