Home>Article>Backend Development> PHP Algorithm Exercise 11: Check whether two given integers are within the specified range
PHP algorithm series continues today~ Then in the previous article "PHP Algorithm Exercise 10: Calculating the Radius and Center Coordinates of a Circle" I introduced to you how to use PHP to calculate the radius and center coordinates of a circle. Interested friends can learn about it~
→Recommendation: "PHP algorithm practice series summary (continuously updated~)"
This article will introduce how to use it. PHP determines whether two given integers are within the specified range!
Specific questionThe description is "How to write a PHP program to check whether two given integers are within the range of 100..200 (inclusive)"?
I believe that everyone will be able to write this implementation method soon. The following is the method I gave, you can refer to it:
The PHP code is as follows:
= 100 && $x <= 200) || ($y >= 100 && $y <= 200); } var_dump(test(100, 199)); var_dump(test(250, 300)); var_dump(test(105, 190));
The printed result is:
boolean true boolean false boolean true
It’s very simple! In the above code, we create a test method and give it two parameters, $x, $y;
The main thing you need to master here is the PHP operator, such as:
Comparison operator:
Greater than or equal to (x >= y): If x is greater than or equal to y, return true;
Less than or equal to (x < ;= y): If x is less than or equal to y, returns true;
Logical operator:
And (x && y): If x If both x and y are true, return true;
or (x || y): If at least one of x and y is true, return true.
Note: return returns program control to the calling module. Will continue with the next expression executed in the calling module.
If the return statement is called in a function, the execution of this function will be ended immediately and its parameters will be returned as the value of the function. return will also terminate the execution of the eval() statement or script file.
Finally, I would like to recommend the latest and most comprehensive "PHP Video Tutorial"~ Come and learn!
The above is the detailed content of PHP Algorithm Exercise 11: Check whether two given integers are within the specified range. For more information, please follow other related articles on the PHP Chinese website!