Associative Arrays in PHP

PHPServer Side ProgrammingProgramming

Associative array will have their index as string so that you can establish a strong association between key and values. The associative arrays have names keys that is assigned to them.

Let us see an example−

echo "Value 1 = " .reset($arr); ?> Output This will produce the following output− Value 1 = 150 Example Let us now see another example − Live Demo <?php$salaries = array("jack" => 2000, "qadir" => 1000);
echo "Salary of jack is ". $salaries['jack'] . "\n";$salaries['jack'] = "high";
$salaries['tom'] = "low"; echo "Salary of jack is ".$salaries['jack'] . "\n";
?>

Output

This will produce the following output−

Salary of jack is 2000
Salary of jack is high
Updated on 26-Dec-2019 08:06:50