php - How to tell the season by specified range of dates -


i'm going specify season dates given. have 4 seasons ranging dates (not month). decided use in_array , range() shows nothing.

here's code:

$p1=strtotime("2013-12-13"); $p2=strtotime("2014-02-20"); $h1a=strtotime("2014-02-21"); $h1b=strtotime("2014-04-31"); $l1=strtotime("2013-05-01"); $l2=strtotime("2013-10-31"); $h2a=strtotime("2013-11-01"); $h2b=strtotime("2013-12-19");   $today=strtotime(date("y-m-d"));  if(in_array($today, range($p1, $p2))){     echo "peak"; }elseif(in_array($today, range($h1a, $h1b))){     echo "hi1"; }elseif(in_array($today, range($l1, $l2))){     echo "low"; }else(in_array($today, range($h2a, $h2b))){     echo "h2"; } 

could guys please improve code.

regards,

i've got own solution now. trials. code adapted : http://css-tricks.com/snippets/php/change-graphics-based-on-season/

<? function current_season() {        // locate icons        $icons = array(                "peak" => "peak season",                "low" => "low season",                "high1" => "high1 season",                "high2" => "high2 season"        );         // today's date - number        $day = date("z");         //  days of peak        $peak_starts = date("z", strtotime("december 13"));        $peak_ends   = date("z", strtotime("february 20"));         //  days of low        $low_starts = date("z", strtotime("may 1"));        $low_ends   = date("z", strtotime("october 31"));         //  days of high        $high_starts = date("z", strtotime("february 21"));        $high_ends   = date("z", strtotime("april 31"));         //  if $day between days of peak, low, high, , winter        if( $day >= $peak_starts && $day <= $peak_ends ) :                $season = "peak";        elseif( $day >= $low_starts && $day <= $low_ends ) :                $season = "low";        elseif( $day >= $high1_starts && $day <= $high1_ends ) :                $season = "high";        else :                $season = "high2";        endif;         $image_path = $icons[$season];         echo $image_path; } echo current_season(); ?> 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -