What is the difference between encoding an array to JSON and decoding it back to an array in PHP?

When encoding an array to JSON in PHP, you are converting the array into a JSON string that can be easily transmitted or stored. When decoding the JSON back to an array, you are converting the JSON string back into its original array format for further manipulation or processing.

// Encoding an array to JSON
$array = ['apple', 'banana', 'cherry'];
$json = json_encode($array);

// Decoding JSON back to an array
$decodedArray = json_decode($json, true);

print_r($decodedArray);