Seasons

<?php /** * Get current season * * @param string $hemisphere Opções válidas: 'norte', 'sul' * @return string */ function getSeason($hemisphere) { $date = date('Y-m-d'); $seasons = [ 'norte' => [ 'verao' => [date('Y').'-06-21', date('Y').'-09-22'], 'outono' => [date('Y').'-09-23', date('Y').'-12-20'], 'inverno' => [date('Y').'-12-21', date('Y').'-03-20'], 'primavera' => [date('Y').'-03-21', date('Y').'-06-20'] ], 'sul' => [ 'verao' => [date('Y').'-12-21', date('Y').'-03-20'], 'outono' => [date('Y').'-03-21', date('Y').'-06-20'], 'inverno' => [date('Y').'-06-21', date('Y').'-09-22'], 'primavera' => [date('Y').'-09-23', date('Y').'-12-20'] ] ]; foreach($seasons[$hemisphere] as $key => $val){ if(($hemisphere == 'norte' && $key == 'inverno') || ($hemisphere == 'sul' && $key == 'verao')){ if($date >= $val[0] || $date <= $val[1]){ return $key; } }else{ if($date >= $val[0] && $date <= $val[1]){ return $key; } } } return false; }
Get current season in Portuguese.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.