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

青灯夜游
Release: 2023-03-13 06:54:02
Original
2410 people have browsed it

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>";
	}
}
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template