
Associative Array Example in PHP
Associative arrays in PHP allow you to store data using meaningful keys instead of numeric indexes. This makes your code more readable and easier to manage, especially when working with structured data like user details, settings, or configuration values.
In this example, we’ll see how to create an associative array in PHP, access its values using keys, and display the output. This basic concept is widely used in real-world PHP applications and is essential for every PHP developer to understand.
<?php
$data = array(
'name'=>"John Doe",
'age'=>20,
"company_name"=> "XYZ"
);
echo $data['name']. "\n";
echo $data['age']. "\n";
echo $data['company_name']. "\n";
?>
Output:
$ php associative_array.php John Doe 20 XYZ
- END -



