Home >Backend Development >PHP Problem >How to output all numbers within 80 that are divisible by 3 in php
In PHP, you can use for loops and if judgment statements to output all numbers within 80 that are divisible by 3. The syntax "for($i=1;$i
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php output is within 80 All numbers divisible by 3
Implementation idea:
Use for loop statement to control the divisibility range (1~80)
In the loop body, use the if statement to perform integer division judgment, $i%3==0
Implementation code:
<?php for($i=1;$i<=80;$i++){ if($i%3==0){ echo $i."<br>"; } } ?>
Output result:
Explanation: %
is the remainder operation
If the remainder is 0, it is divisible.
Note: Use % in arithmetic operators to find remainder. If the dividend ($a) is a negative number, the result obtained is also a negative value.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to output all numbers within 80 that are divisible by 3 in php. For more information, please follow other related articles on the PHP Chinese website!