What is the correct way to extract data from a JSON string in PHP?

To extract data from a JSON string in PHP, you need to decode the JSON string using the `json_decode` function. This will convert the JSON string into a PHP array or object, allowing you to access the data within it. You can then access specific values by using array or object notation.

$jsonString = '{"name": "John", "age": 30}';
$data = json_decode($jsonString);

echo $data->name; // Output: John
echo $data->age; // Output: 30