+ 1
What's a real life use case for modulus?
4 ответов
+ 3
@Scott Noroozi
# say Sunday is day zero, Monday is day one, etc
$what_day = $today % 7;
# if $today is 7, then 7 % 7 = 0 so it's a Sunday.
# if $today is 8, then 8 % 7 = 1 so it's a Monday.
+ 1
If today is Monday then 7 days from now it is Monday again.....and so on. This mod 7
0
@David Rodriguez thanks man. so how would you write that if you don't mind sharing?
0
what if today 2?