Why Arrays in PHP are Not Real Array Data Structures
PHP arrays are a crucial part of the language. Even though they’re called “arrays,” they’re different from what most other languages call arrays. In this piece, we’ll focus on these differences and explain why PHP arrays aren’t typical array structures. Dive in and discover the unique world of PHP arrays!
Disclaimer: this post does not says that arrays in PHP are bad, it compares them to Array data structures that any computer science book/article shows.
Even tough you can try to use them as the common sense definition of an Array, under the hood, the way PHP handles them is the same.
The own PHP official documentation states “An array in PHP is actually an ordered map.” Source: https://www.php.net/manual/en/language.types.array.php
Introduction: Understanding Arrays in Data Structures
Definition
Traditionally, an array is a collection of elements with:
- Homogeneity: Same data type.
- Fixed Size: Unchangeable after creation.
- Indexing: Continuous integers, usually starting from 0.
- Contiguous Memory Allocation: Adjacent storage of elements.