Skip to content

PHP Accessing Associative Arrays

Syntax

Elements in an associative array are accessed using their string keys instead of numeric indices.

$arrayName["key"];

Example

// Declaring an associative array
$person = ["name" => "Alice", "age" => 25, "city" => "New York"];
// Accessing elements
echo $person["name"]; // Outputs: Alice
echo $person["age"]; // Outputs: 25