How can the PHP function json_decode be utilized to extract specific data from a JSON-like structure in PHP?
To extract specific data from a JSON-like structure in PHP using the json_decode function, you can decode the JSON string into an associative array and then access the desired data using array keys. You can also use the second parameter of json_decode to specify that the result should be returned as an associative array.
// JSON-like structure
$jsonData = '{"name": "John Doe", "age": 30, "city": "New York"}';
// Decode the JSON string into an associative array
$data = json_decode($jsonData, true);
// Access specific data
$name = $data['name'];
$age = $data['age'];
$city = $data['city'];
echo "Name: " . $name . "<br>";
echo "Age: " . $age . "<br>";
echo "City: " . $city;