How can the json_encode and json_decode functions be utilized effectively in PHP to handle JSON data?

To handle JSON data effectively in PHP, you can use the json_encode function to convert PHP data structures into a JSON format and the json_decode function to convert JSON data back into PHP data structures. This is particularly useful when working with APIs that return data in JSON format or when you need to store or transmit data in a standardized format.

// Example of using json_encode to convert PHP data to JSON
$data = ['name' => 'John', 'age' => 30];
$jsonData = json_encode($data);
echo $jsonData;

// Example of using json_decode to convert JSON data to PHP data
$jsonData = '{"name": "John", "age": 30}';
$data = json_decode($jsonData, true);
echo $data['name']; // Output: John