How to divide minute by 3 in PHP ?

201 views Asked by At

How to divide time by 3? I know $minute%3==0 could work if minute is 0,3,9,12,15...

But how to judge if minute is 1,4,10,13,16, if minute is 2,5,11,14,17?

Thanks.

$minute = date('i');
if($minute%3==0){
  //if minute is 0,3,9,12,15...do something
}else if($minute%3+1==0){
  //if minute is 1,4,10,13,16...do something
}else if($minute%3+2==0){
  //if minute is 2,5,11,14,17...do something
}
1

There are 1 answers

0
feddus On BEST ANSWER

Do it by checking the remainder of dividing by 3:

$minute = date('i');
if($minute%3==0){
  //if minute is 0,3,9,12,15...do something
}else if($minute%3==1){
  //if minute is 1,4,10,13,16...do something
}else if($minute%3==2){
  //if minute is 2,5,11,14,17...do something
}