Home >Backend Development >PHP Problem >How to output all numbers within 80 that are divisible by 3 in php

How to output all numbers within 80 that are divisible by 3 in php

青灯夜游
青灯夜游Original
2021-09-28 16:47:052378browse

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

How to output all numbers within 80 that are divisible by 3 in php

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:

How to output all numbers within 80 that are divisible by 3 in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn