Home >Backend Development >PHP Problem >How to determine whether two numbers are remainder after division in php

How to determine whether two numbers are remainder after division in php

青灯夜游
青灯夜游Original
2022-02-10 18:10:392583browse

php method to determine whether the division is remainder: 1. Use the "%" operator to calculate the division of two numbers and obtain the remainder value. The syntax is "Number 1% Number 2"; 2. Use the if statement and " !="operator can be used to determine whether the obtained remainder value is 0, the syntax is "if (remainder value!=0){//division has remainder}else{//division has no remainder}".

How to determine whether two numbers are remainder after division in php

The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer

Determine whether the division is sufficient in PHP, or It is to determine whether the remainder of the division of two numbers is 0.

So we need to first use the "%" operator to find the remainder, and then use the "!=" or "==" operator to determine whether the remainder is 0.

Implementation code:

<?php
header("Content-type:text/html;charset=utf-8");
$num1 = 12;
$num2 = 3;
$num=$num1%$num2;
if($num!=0){
	echo "相除有余";
}else{
	echo "相除没有余";
}
?>

How to determine whether two numbers are remainder after division in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine whether two numbers are remainder after division 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