PHP’s numerically indexed array begins with which position?

A numerically indexed array in PHP begins with position 0, not 1. The first element has the key 0, the second has 1, and so on.

<?php
$array = [15, 80, 67, 33];

echo $array[0] . "<br>";
echo $array[3];
?>

Output:

Tutorials Class - Output Window

15
33

This array has 4 elements, so the keys are 0, 1, 2 and 3. If you try $array[4], PHP shows a warning “Undefined array key 4”, because there is no element at that position. The last key is always count($array) - 1.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.