What function can be used to decode JSON data in PHP?
To decode JSON data in PHP, you can use the `json_decode()` function. This function takes a JSON string as input and converts it into a PHP variable (array or object) that can be easily accessed and manipulated in your code.
$json_data = '{"name": "John", "age": 30, "city": "New York"}';
$decoded_data = json_decode($json_data);
// Accessing the decoded data
echo $decoded_data->name; // Output: John
echo $decoded_data->age; // Output: 30
echo $decoded_data->city; // Output: New York
Related Questions
- How can multiple else branches without if conditions be resolved in PHP code?
- Are there any best practices for securely storing user authentication tokens in PHP cookies for automatic login functionality?
- How can PHP be optimized to ensure that only the necessary content is displayed without duplication or errors?