Sending Data in JSON Format in PHP
When a website is running, it often happens that some URLs return not HTML code, but JSON. Let's write an example of such a page:
<?php
$data = [1, 2, 3];
$json = json_encode($data);
echo $json;
?>
A more correct approach would be to send the appropriate HTTP header as well:
<?php
$data = [1, 2, 3];
$json = json_encode($data);
header('Content-Type: application/json');
echo $json;
?>
When accessing a certain file,
create an array with numbers from 1
to 100 and output it in JSON format.