What is the correct syntax for accessing specific values in an associative array in PHP?
When accessing specific values in an associative array in PHP, you need to use the key associated with the value you want to retrieve. You can access the value by using square brackets and specifying the key within them. This allows you to easily retrieve and work with specific values stored in an associative array.
// Associative array
$person = array("name" => "John", "age" => 30, "city" => "New York");
// Accessing specific values
$name = $person["name"];
$age = $person["age"];
$city = $person["city"];
// Outputting the values
echo $name; // Output: John
echo $age; // Output: 30
echo $city; // Output: New York
Related questions
-
MVC architecture Composer PHPUnit testing
-
MD5 base64 password encryption
-
multilingual website language-specific content PHP