What is the purpose of using json_decode in the given PHP code?

The purpose of using json_decode in the given PHP code is to convert a JSON string into a PHP variable. This is useful when you need to work with JSON data within a PHP script, as json_decode allows you to easily access and manipulate the data in a structured format.

// JSON data to be decoded
$json_data = '{"name": "John", "age": 30, "city": "New York"}';

// Decode the JSON data into a PHP variable
$decoded_data = json_decode($json_data);

// Access the decoded data
echo $decoded_data->name; // Output: John
echo $decoded_data->age; // Output: 30
echo $decoded_data->city; // Output: New York