How can PHP functions like json_decode and json_encode be utilized effectively in handling JSON data?
When working with JSON data in PHP, the functions json_decode and json_encode can be used effectively to decode JSON data into PHP arrays or objects, and encode PHP arrays or objects into JSON format. This allows for easy manipulation and transfer of data in JSON format.
// Example of decoding JSON data into a PHP array
$jsonData = '{"name": "John", "age": 30, "city": "New York"}';
$decodedData = json_decode($jsonData, true);
// Example of encoding a PHP array into JSON format
$arrayData = ['name' => 'Jane', 'age' => 25, 'city' => 'Los Angeles'];
$encodedData = json_encode($arrayData);
// Output the decoded and encoded data
var_dump($decodedData);
echo $encodedData;