Back to course

Introduction to Indexed Arrays

PHP: The Complete 0 to Hero Bootcamp

21. Introduction to Indexed Arrays

Arrays are special variables that can hold more than one value under a single name. Indexed arrays use numbers (starting from 0) as keys to access the values.

Creating Indexed Arrays

PHP offers two main syntaxes for creating arrays:

  1. The traditional array() constructor: php

  2. The short array syntax (recommended, PHP 5.4+): php

Accessing and Modifying Elements

Elements are accessed using their index, enclosed in square brackets [].

php

"; print_r($planets); echo ""; ?>