Skip to content

PHP Accessing Indexed Arrays

Syntax

Elements in an indexed array in PHP can be accessed using their numeric indices, starting from 0.

$element = $arrayName[index];

Example

// Declaring an indexed array
$fruits = ["Apple", "Banana", "Cherry"];
// Accessing elements
echo $fruits[0]; // Outputs: Apple
echo $fruits[1]; // Outputs: Banana
// Modifying an element
$fruits[2] = "Blueberry";
echo $fruits[2]; // Outputs: Blueberry