To access array elements using index in PHP, you can use the square bracket notation with the index of the element.
In this example,
$arr
with a few elements.<?php
$arr = array("apple", "banana", "cherry");
$element = $arr[1];
echo $element;
?>
banana
In this example,
$arr
with key-value pairs.<?php
$arr = array("first" => "apple", "second" => "banana", "third" => "cherry");
$element = $arr["second"];
echo $element;
?>
banana
In this tutorial, we learned How to Access Array Elements using Index in PHP language with well detailed examples.