Question

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
}
Was it helpful?

Solution

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top