php method to determine odd or even number: 1. Create a new php file; 2. Define a variable; 3. Use the "%" modulo operator to modulo the number 10 to 2; 4. Use the if statement Determine the result of the previous step and output the prompt through echo.
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
How to determine odd or even number in php?
Create a new php file named test.php to explain how php determines whether a number is even or odd.
In the test.php file, use the header() method to set the encoding format of the page to utf-8.
In the test.php file, define a variable to save the number 10 for testing.
In the test.php file, use the "%" modulo operator to modulo the number 10 to 2. If the result is 0, it is an even number, otherwise it is an odd number.
In the test.php file, use the if statement to determine the result of the previous step and output the prompt through echo.
Open the test.php file in the browser to view the results.
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to determine odd or even number in php. For more information, please follow other related articles on the PHP Chinese website!