In php, numerically indexed arrays begin with position 0 because php is a zero-based programming language.
$array = array(101,202,303);
print_r($array);
// Output:
Array
(
[0] => 101
[1] => 202
[2] => 303
)
Depending on which programming language you use, there are sometimes different conventions and behaviors which you need to know.
One such piece of information which is valuable and important to know is which position arrays start with.
Most programming languages are zero-based and have arrays which start with the index 0.
PHP is a zero-based programming language and because of this, by default, numerically indexed arrays begin with position 0.
Below is an example showing you that numerically indexed arrays in PHP begin with position 0.
$array = array(101,202,303);
print_r($array);
// Output:
Array
(
[0] => 101
[1] => 202
[2] => 303
)
Why Do Most Programming Languages Use Zero as Beginning Index of Arrays?
When you start to learn multiple programming languages, you will notice that many programming languages are zero-based. For example, PHP, Python, JavaScript, C, C++, Java are all zero-based programming languages.
Most programming languages are zero-based because it is has been argued that starting with zero makes programming much easier than if you start with 1 or any other number.
Arguably the most powerful argument on this subject comes from Edsger W. Dijkstra’s article “Why numbering should start at zero”.
Hopefully this article has been useful for you to learn that in php, numerically indexed arrays begin with position 0