How to get through all cases if they are true PHP

I want to know if there is a way to continue all three cases if they are all true, but using break, because as an example, if the first case is true, the second case is false, and the third is also false, and I do not use break , it will still be skipped. Change strtotime from October 6, 2014 and you will see what I mean

$date = strtotime("1 October 2014"); 
switch($date) {  
     case (date('l', $date) == 'Monday'): //case 1: If the current day is Monday
      echo "weekly<br>";
     break;

     case (date('d', $date) == '01'):  //case 2: If the current day of the month is 1
      echo "monthly<br>";                       
     break;

    case ( ((date('n') % 3) == '1') && (date('d') == '01') ): //case 3: If a quart of the year has just passed,and we are in the first day of a new quart
      echo 'quarterly<br>';     
    break;   

}

Any suggestion??? And if this is not possible using the switch, how can I do this if, to execute a line of code 3 times, one for each case.

+4
source share
4 answers

to try

$date = strtotime("1 October 2014"); 

     if (date('l', $date) == 'Monday'){ //case 1: If the current day is Monday
      echo "weekly<br>";
     }
     if (date('d', $date) == '01'){  //case 2: If the current day of the month is 1
      echo "monthly<br>";                       
     }
    if ( ((date('n', $date) % 3) == '1') && (date('d', $date) == '01') ){ //case 3: If a quart of the year has just passed,and we are in the first day of a new quart
      echo 'quarterly<br>';   
    }  
+1
source

, switch - - , "". if.

+3

UPDATE: :

$date = strtotime("1 September 2014");
$continue = true;

if(date('l', $date) == 'Monday'): //case 1: If the current day is Monday
    echo "weekly<br>";
else:
    $continue = false;
endif;

if(date('d', $date) == '01' && $continue):  //case 2: If the current day of the month is 1
    echo "monthly<br>";
else:
    $continue = false;
endif;

if( ((date('n') % 3) == '1') && (date('d') == '01') && $continue ): //case 3: If a quart of the year has just passed,and we are in the first day of a new quart
    echo 'quarterly<br>'; 
endif;


OLD VERSION ( ): , :

function sequencer($date_string)
{
    $date = strtotime($date_string);

    if(date('l', $date) == 'Monday'): //case 1: If the current day is Monday
        echo "weekly<br>";
    else:
        return;
    endif;

    if(date('d', $date) == '01'):  //case 2: If the current day of the month is 1
        echo "monthly<br>";
    else:
        return;
    endif;

    if( ((date('n') % 3) == '1') && (date('d') == '01') ): //case 3: If a quart of the year has just passed,and we are in the first day of a new quart
        echo 'quarterly<br>'; 
    else:
        return;
    endif;
}

sequencer("1 October 2014");

, , strotime() .

+1

- , , , -, .

, echo , :

<?php

    $date = strtotime("6 October 2014");

    echo (date('l', $date) == 'Monday')?"Weekly<br>":"";
    echo (date('d', $date) == '01') == 'Monday')?"Monthly<br>":"";
    echo ( ((date('n') % 3) == '1') && (date('d') == '01') ) == 'Monday')?"Quarterly<br>":"";

?>

, .

0

All Articles