Home>Article>Backend Development> PHP Algorithm Exercise 13: Determine whether the values in the ones digits of multiple non-negative integers are the same

PHP Algorithm Exercise 13: Determine whether the values in the ones digits of multiple non-negative integers are the same

藏色散人
藏色散人 Original
2021-08-31 09:55:36 2193browse

In the previous article "PHP Algorithm Exercise 12: Get the absolute value between n and 51 and return the value as required" I introduced you how to get the absolute value between n and 51 And return the value as required. Friends who are interested can learn about it~

This article continues the PHP algorithm exercise series. Today’s theme is "Determining whether the values of the ones digits of multiple non-negative integers are the same." . [Recommended:PHP algorithm exercise series summary (continuously updated~)]

Specific description of the problem: "How to write a PHP program to check two or more given non-negative integers Whether the values in the ones digits are the same."

Related introduction: Tens, hundreds, millions...are all counting units; units, tens, hundreds, thousands, and ten thousand are all digits. Counting units and digits are two completely different concepts. The digit refers to the name of the position of the number, while the counting unit refers to the meaning of the number in the exponent digit. For example: 9063200 is read as nine hundred and sixty-three thousand two hundred, ten thousand, Hundreds are the unit of counting. The number "9" is in the millions place, and "6" is in the tens of thousands place. These are the digits.

The following is the implementation method I gave:

The PHP code is as follows:

"; var_dump(test(11, 22, 31))."
"; var_dump(test(11, 22, 33))."
";

The execution result is as follows:

boolean true boolean true boolean false

Introduction to common operators:

x y: addition, the sum of x and y 2 2, 4;

x - y: subtraction, the difference between x and y 5 - 2, 3 ;

x * y; multiplication, the product of x and y 5 * 2, 10;

x / y: division, the quotient of x and y 15 / 5, 3;

x % y: modulo (remainder of division), the remainder of x divided by y, 5 % 2;

x || y: or, if at least one of x and y is true, return true .

Finally, I would like to recommend the latest and most comprehensive "PHP Video Tutorial"~ Come and learn!

The above is the detailed content of PHP Algorithm Exercise 13: Determine whether the values in the ones digits of multiple non-negative integers are the same. 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