Modules | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Modules

$x=14; $y=3; echo$x % $y; Why the output is 2??

2nd Jan 2017, 9:18 AM
Bakhtiyar Malik
Bakhtiyar Malik - avatar
2 ответов
+ 2
The module operator calculates the remainder of a division. 14 / 3 = 4, with a remainder of 2
2nd Jan 2017, 9:42 AM
Dao
Dao - avatar
+ 1
Modulo calculates the normal integer division which means your result has no decimals. Your result from integer division consists of two different parts. The First part is your normal divisor, the second the rest, in other words the result of a modulo calculation. Here are some examples: 0/1 == 0 --> 0%1 == 0 4/2 == 2 --> 0%2 == 0 5/2 == 2 rest 1 --> 5%2 == 1 6/3 == 2 --> 6%3 == 0 7/3 == 2 rest 1 --> 7%3 == 1 8/3 == 2 rest 2 --> 8%3 == 2
2nd Jan 2017, 9:46 AM
Andreas K
Andreas K - avatar