What is the purpose of using json_decode in PHP?
When working with JSON data in PHP, you may need to convert a JSON string into a PHP variable for further processing. This is where the json_decode function comes in handy. It allows you to decode a JSON string and convert it into a PHP variable, such as an array or an object.
$jsonString = '{"name": "John", "age": 30, "city": "New York"}';
$decodedData = json_decode($jsonString);
// Accessing the decoded data
echo $decodedData->name; // Output: John
echo $decodedData->age; // Output: 30
echo $decodedData->city; // Output: New York