Created
June 23, 2014 14:31
-
-
Save bijayrungta/d3586b30191562e677cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get upcomming match schedule | |
*/ | |
function getNextMatches($referenceTime = null) | |
{ | |
$matchSchedule = array( | |
"2014-06-13 01:30:00" => array('team1' => 'BRA', 'team2' => 'CRO', 'date' => '2014-06-13 01:30:00', 'team1Class' => 'brazil', 'team2Class' => 'croatia'), | |
"2014-06-13 21:30:00" => array('team1' => 'MEX', 'team2' => 'CMR', 'date' => '2014-06-13 21:30:00', 'team1Class' => 'mexico', 'team2Class' => 'cameroon'), | |
"2014-06-14 00:30:00" => array('team1' => 'SPA', 'team2' => 'NET', 'date' => '2014-06-14 00:30:00', 'team1Class' => 'spain', 'team2Class' => 'netherlands'), | |
"2014-06-14 03:30:00" => array('team1' => 'CHI', 'team2' => 'AUS', 'date' => '2014-06-14 03:30:00', 'team1Class' => 'chile', 'team2Class' => 'australia'), | |
"2014-06-14 21:30:00" => array('team1' => 'COL', 'team2' => 'GRE', 'date' => '2014-06-14 21:30:00', 'team1Class' => 'colombia', 'team2Class' => 'greece'), | |
"2014-06-15 00:30:00" => array('team1' => 'URU', 'team2' => 'CRC', 'date' => '2014-06-15 00:30:00', 'team1Class' => 'uruguay', 'team2Class' => 'costa-rica'), | |
"2014-06-15 03:30:00" => array('team1' => 'ENG', 'team2' => 'ITA', 'date' => '2014-06-15 03:30:00', 'team1Class' => 'england', 'team2Class' => 'italy'), | |
"2014-06-15 06:30:00" => array('team1' => 'CIV', 'team2' => 'JAP', 'date' => '2014-06-15 06:30:00', 'team1Class' => 'cote', 'team2Class' => 'japan'), | |
"2014-06-15 21:30:00" => array('team1' => 'SWI', 'team2' => 'ECU', 'date' => '2014-06-15 21:30:00', 'team1Class' => 'switzerland', 'team2Class' => 'ecuador'), | |
"2014-06-16 00:30:00" => array('team1' => 'FRA', 'team2' => 'HON', 'date' => '2014-06-16 00:30:00', 'team1Class' => 'france', 'team2Class' => 'honduras'), | |
"2014-06-16 03:30:00" => array('team1' => 'ARG', 'team2' => 'BIH', 'date' => '2014-06-16 03:30:00', 'team1Class' => 'argentina', 'team2Class' => 'bosnia'), | |
"2014-06-16 21:30:00" => array('team1' => 'GER', 'team2' => 'POR', 'date' => '2014-06-16 21:30:00', 'team1Class' => 'germany', 'team2Class' => 'portugal'), | |
"2014-06-17 00:30:00" => array('team1' => 'IRN', 'team2' => 'NGA', 'date' => '2014-06-17 00:00:00', 'team1Class' => 'iran', 'team2Class' => 'nigeria'), | |
"2014-06-17 03:30:00" => array('team1' => 'GHA', 'team2' => 'USA', 'date' => '2014-06-17 03:30:00', 'team1Class' => 'ghana', 'team2Class' => 'usa'), | |
"2014-06-17 21:30:00" => array('team1' => 'BEL', 'team2' => 'ALG', 'date' => '2014-06-17 21:30:00', 'team1Class' => 'belgium', 'team2Class' => 'algeria'), | |
"2014-06-18 00:30:00" => array('team1' => 'BRA', 'team2' => 'MEX', 'date' => '2014-06-18 00:30:00', 'team1Class' => 'brazil', 'team2Class' => 'mexico'), | |
"2014-06-18 03:30:00" => array('team1' => 'RUS', 'team2' => 'KOR', 'date' => '2014-06-17 03:30:00', 'team1Class' => 'russia', 'team2Class' => 'korea'), | |
"2014-06-18 21:30:00" => array('team1' => 'AUS', 'team2' => 'NET', 'date' => '2014-06-18 21:30:00', 'team1Class' => 'australia', 'team2Class' => 'netherlands'), | |
"2014-06-19 00:30:00" => array('team1' => 'SPA', 'team2' => 'CHI', 'date' => '2014-06-19 00:30:00', 'team1Class' => 'spain', 'team2Class' => 'chile'), | |
"2014-06-19 03:30:00" => array('team1' => 'CMR', 'team2' => 'CRO', 'date' => '2014-06-19 03:30:00', 'team1Class' => 'cameroon', 'team2Class' => 'croatia'), | |
"2014-06-19 21:30:00" => array('team1' => 'JAP', 'team2' => 'GRE', 'date' => '2014-06-19 21:30:00', 'team1Class' => 'japan', 'team2Class' => 'greece'), | |
"2014-06-20 00:30:00" => array('team1' => 'URU', 'team2' => 'ENG', 'date' => '2014-06-20 00:30:00', 'team1Class' => 'uruguay', 'team2Class' => 'england'), | |
"2014-06-20 03:30:00" => array('team1' => 'JAP', 'team2' => 'GRE', 'date' => '2014-06-20 03:30:00', 'team1Class' => 'japan', 'team2Class' => 'greece'), | |
"2014-06-20 21:30:00" => array('team1' => 'ITA', 'team2' => 'CRC', 'date' => '2014-06-20 21:30:00', 'team1Class' => 'italy', 'team2Class' => 'costa-rica'), | |
"2014-06-21 00:30:00" => array('team1' => 'SWI', 'team2' => 'FRA', 'date' => '2014-06-21 00:30:00', 'team1Class' => 'switzerland', 'team2Class' => 'france'), | |
"2014-06-21 03:30:00" => array('team1' => 'HON', 'team2' => 'ECU', 'date' => '2014-06-21 03:30:00', 'team1Class' => 'honduras', 'team2Class' => 'ecuador'), | |
"2014-06-21 21:30:00" => array('team1' => 'ARG', 'team2' => 'IRN', 'date' => '2014-06-21 21:30:00', 'team1Class' => 'argentina', 'team2Class' => 'iran'), | |
"2014-06-22 00:30:00" => array('team1' => 'GER', 'team2' => 'GHA', 'date' => '2014-06-22 00:30:00', 'team1Class' => 'germany', 'team2Class' => 'ghana'), | |
"2014-06-22 03:30:00" => array('team1' => 'NGA', 'team2' => 'BIH', 'date' => '2014-06-22 03:30:00', 'team1Class' => 'nigeria', 'team2Class' => 'bosnia'), | |
"2014-06-22 21:30:00" => array('team1' => 'BEL', 'team2' => 'RUS', 'date' => '2014-06-22 21:30:00', 'team1Class' => 'belgium', 'team2Class' => 'russia'), | |
"2014-06-23 00:30:00" => array('team1' => 'KOR', 'team2' => 'ALG', 'date' => '2014-06-23 00:30:00', 'team1Class' => 'korea', 'team2Class' => 'algeria'), | |
"2014-06-23 03:30:00" => array('team1' => 'USA', 'team2' => 'POR', 'date' => '2014-06-23 03:30:00', 'team1Class' => 'usa', 'team2Class' => 'portugal'), | |
"2014-06-23 21:30:00" => array('team1' => 'AUS', 'team2' => 'SPA', 'date' => '2014-06-23 21:30:00', 'team1Class' => 'australia', 'team2Class' => 'spain'), | |
"2014-06-23 21:30:01" => array('team1' => 'NET', 'team2' => 'CHI', 'date' => '2014-06-23 21:30:00', 'team1Class' => 'netherlands', 'team2Class' => 'chile'), | |
"2014-06-24 01:30:00" => array('team1' => 'CMR', 'team2' => 'BRA', 'date' => '2014-06-24 01:30:00', 'team1Class' => 'cameroon', 'team2Class' => 'brazil'), | |
"2014-06-24 01:30:01" => array('team1' => 'CRO', 'team2' => 'MEX', 'date' => '2014-06-24 01:30:00', 'team1Class' => 'croatia', 'team2Class' => 'mexico'), | |
"2014-06-24 21:30:00" => array('team1' => 'ITA', 'team2' => 'URU', 'date' => '2014-06-24 21:30:00', 'team1Class' => 'italy', 'team2Class' => 'uruguay'), | |
"2014-06-24 21:30:01" => array('team1' => 'CRC', 'team2' => 'ENG', 'date' => '2014-06-24 21:30:00', 'team1Class' => 'costa-rica', 'team2Class' => 'england'), | |
"2014-06-25 00:30:00" => array('team1' => 'JAP', 'team2' => 'COL', 'date' => '2014-06-25 00:30:00', 'team1Class' => 'japan', 'team2Class' => 'colombia'), | |
"2014-06-25 01:30:00" => array('team1' => 'GRE', 'team2' => 'CIV', 'date' => '2014-06-25 01:30:00', 'team1Class' => 'greece', 'team2Class' => 'cote'), | |
"2014-06-25 21:30:00" => array('team1' => 'NGA', 'team2' => 'ARG', 'date' => '2014-06-25 21:30:00', 'team1Class' => 'nigeria', 'team2Class' => 'argentina'), | |
"2014-06-25 21:30:01" => array('team1' => 'BIH', 'team2' => 'IRN', 'date' => '2014-06-25 21:30:00', 'team1Class' => 'bosnia', 'team2Class' => 'iran'), | |
"2014-06-26 00:30:00" => array('team1' => 'HON', 'team2' => 'SWI', 'date' => '2014-06-26 00:30:00', 'team1Class' => 'honduras', 'team2Class' => 'switzerland'), | |
"2014-06-26 01:30:00" => array('team1' => 'ECU', 'team2' => 'FRA', 'date' => '2014-06-26 01:30:00', 'team1Class' => 'ecuador', 'team2Class' => 'france'), | |
"2014-06-26 21:30:00" => array('team1' => 'HON', 'team2' => 'SWI', 'date' => '2014-06-26 21:30:00', 'team1Class' => 'honduras', 'team2Class' => 'switzerland'), | |
"2014-06-26 21:30:01" => array('team1' => 'POR', 'team2' => 'GHA', 'date' => '2014-06-26 21:30:00', 'team1Class' => 'portugal', 'team2Class' => 'ghana'), | |
"2014-06-27 01:30:00" => array('team1' => 'ALG', 'team2' => 'RUS', 'date' => '2014-06-27 01:30:00', 'team1Class' => 'algeria', 'team2Class' => 'russia'), | |
"2014-06-27 01:30:01" => array('team1' => 'KOR', 'team2' => 'BEL', 'date' => '2014-06-27 01:30:00', 'team1Class' => 'korea', 'team2Class' => 'belgium'), | |
); | |
if (!$referenceTime) { | |
$referenceTime = date('Y-m-d H:i:s'); | |
} | |
$offset = 0; | |
foreach ($matchSchedule as $matchTime => $matchInfo) { | |
if ($referenceTime < $matchTime) { | |
break; | |
} | |
$offset ++; | |
} | |
return array_slice($matchSchedule, $offset, 5, true); | |
} | |
echo '<pre>'; | |
echo '<h3>Next 5 Matches from NOW</h3>'; | |
print_r(getNextMatches()); | |
$aTestCases = array( | |
'2014-06-30 15:23:25', | |
'2014-07-05 15:23:25', | |
); | |
foreach ($aTestCases as $time ) { | |
echo "<h3>Next 5 Matches from {$time}</h3>"; | |
print_r(getNextMatches($time)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment