Access Array Items in PHP

You can access array items using their index for indexed arrays or their key for associative arrays.

Example of Accessing Array Items

<?php
$colors = array("red", "green", "blue");
echo $colors[0]; // Outputs: red

$person = array("name" => "John", "age" => 30);
echo $person['name']; // Outputs: John
?>

Output:

red
John

Explanation: This example demonstrates how to access an item in an indexed and associative array.