Home >Backend Development >PHP Problem >PHP Algorithm Exercise 13: Determine whether the values in the ones digits of multiple non-negative integers are the same
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:
<?php function test($x, $y, $z) { return $x % 10 == $y % 10 || $x % 10 == $z % 10 || $y % 10 == $z % 10; } var_dump(test(11, 21, 31))."<br>"; var_dump(test(11, 22, 31))."<br>"; var_dump(test(11, 22, 33))."<br>";
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!