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
PHP Arrays
PHP Array Functions
Exercises & Assignments
Remove specific element by value from an array in PHP?
PHP Array to String Conversion (favourite colours chosen by user)
How to check if an array is a subset of another in PHP?
Interview Questions & Answers
What are the different PHP functions to sort an array?
PHP’s numerically indexed array begins with which position?
Which PHP function inserts an element to the end of an array?
Which PHP function can be used check if variable is an array?
How many types of arrays are available in PHP?
What is the use of array_chunk() function in PHP?
What is the use of in_array() function in PHP?