search
HomeBackend DevelopmentPHP ProblemPHP 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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment