What are some common methods for integrating JSON data in PHP and JavaScript for web development projects?

When working on web development projects, it is common to need to integrate JSON data in both PHP and JavaScript. One common method is to use PHP to fetch JSON data from an API or database, then encode it into a JSON string using `json_encode()`. This JSON string can then be passed to JavaScript where it can be parsed using `JSON.parse()`.

// PHP code to fetch JSON data from an API and encode it into a JSON string
$url = 'https://api.example.com/data';
$data = file_get_contents($url);
$json_data = json_encode($data);

echo '<script>';
echo 'var jsonData = JSON.parse(' . $json_data . ');';
echo '</script>';