Advertisement

Google Ad Slot: content-top

PHP Indexed Arrays

~1 min read · PHP
On this page

An indexed array is an array where each element is assigned a numeric index. The index starts from 0 by default and increments by 1 for each subsequent element. Indexed arrays are typically used to store a simple list of items such as numbers, strings, or other data types.

Example
Try it yourself

Access Indexed Arrays


To access an element in an indexed array, you use its index inside square brackets:

Example
Try it yourself

Change Value


You can change an element’s value by specifying its index:

Example
Try it yourself

Loop Through an Indexed Array


You can loop through an indexed array using a foreach loop:

Example
"; } ?>
Try it yourself