What function in PHP can be used to decode a JSON string?
To decode a JSON string in PHP, you can use the `json_decode()` function. This function takes a JSON string as input and returns a PHP variable (array or object) representing the decoded data. This allows you to easily work with JSON data in your PHP code.
$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
Keywords
Related Questions
- What are the best practices for ensuring that each user sees their own personalized signature image in a PHP forum setting?
- How can updating GCC resolve issues related to PHP and Apache compatibility?
- What are common issues faced when using .htaccess for domain redirection and how can they be resolved in PHP?