What potential issues could arise when using PHP to create a JSON API for JS consumption?

One potential issue that could arise when using PHP to create a JSON API for JS consumption is that the JSON response may not be properly formatted, leading to parsing errors on the JavaScript side. To solve this issue, you can use the `json_encode` function in PHP to ensure that the response is correctly encoded as JSON.

// Sample PHP code snippet to create a JSON API response
$data = array(
    'name' => 'John Doe',
    'age' => 30,
    'email' => 'johndoe@example.com'
);

header('Content-Type: application/json');
echo json_encode($data);