Home >Backend Development >PHP Problem >How to find an integer within 100 that is divisible by 3 and has a units digit of 6 in PHP

How to find an integer within 100 that is divisible by 3 and has a units digit of 6 in PHP

青灯夜游
青灯夜游Original
2021-09-18 15:31:463368browse

Implementation method: 1. Use "for($i=1;$i

How to find an integer within 100 that is divisible by 3 and has a units digit of 6 in PHP

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

We can use the for loop to control the range. Use an if statement to find the number of symbolic conditions.

First way:

<?php
for($i=1; $i<100; $i++){
	if($i%3==0&&$i%10==6)
        echo $i, &#39;<br>&#39;;
}
?>

Output result:

How to find an integer within 100 that is divisible by 3 and has a units digit of 6 in PHP

Second One way

<?php
for($i=3; $i<100; $i=$i+3){
    if($i%10==6)
        echo $i, &#39;<br>&#39;;
}  
?>

Output result:

How to find an integer within 100 that is divisible by 3 and has a units digit of 6 in PHP

Related introduction:

PHP (PHP: Hypertext Preprocessor) that is "Hypertext preprocessor" is a scripting language executed on the server side, especially suitable for Web development and can be embedded in HTML. PHP syntax learned the C language, absorbed the characteristics of multiple languages ​​​​of Java and Perl to develop its own unique syntax, and continued to improve itself based on their strengths, such as Java's object-oriented programming. The main goal of the language was originally created to make Developers quickly write high-quality web sites. PHP supports both object-oriented and process-oriented development, and is very flexible in use.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to find an integer within 100 that is divisible by 3 and has a units digit of 6 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