API with Multiple GET Parameters in PHP
Now let's assume that not one parameter, but several will be passed. For example, two numbers:
urlhttp://api.loc/index.php?num1=1&num2=100
Let's return a random number in the range from the first passed number to the second one:
api.loc/index.php<?php
if (isset($_GET['num1']) and isset($_GET['num2'])) {
echo mt_rand($_GET['num1'], $_GET['num2']);
} else {
echo 'error';
}
?>
Задание 1
Create an API with an address, to which two parameters will be passed: dates in the format year-month-day, and in response the number of days between these dates will be returned.
Задание 2
Modify the previous task so that a check for the correct date format is performed.