How can PHP developers ensure the correct Content-Type header is set when outputting JSON data to avoid rendering issues in browsers?

When outputting JSON data in PHP, developers can ensure the correct Content-Type header is set by using the header() function to explicitly specify the content type as "application/json". This helps browsers interpret the response correctly and avoid rendering issues.

<?php
$data = ['name' => 'John', 'age' => 30];
header('Content-Type: application/json');
echo json_encode($data);
?>