What potential issues can arise when saving data from an array to a file in PHP?
One potential issue that can arise when saving data from an array to a file in PHP is that the data may contain special characters or formatting that could cause errors when writing to the file. To solve this issue, you can use the `json_encode()` function to convert the array to a JSON string before writing it to the file. This will ensure that the data is properly formatted and can be easily read back into an array when needed.
$data = array("name" => "John Doe", "age" => 30, "city" => "New York");
$json_data = json_encode($data);
file_put_contents('data.json', $json_data);