58998146 - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of 58998146.php
- <?php
- $today = 'Monday'; // Full day name
- $time = '1205';
- echo "<br/>Day: $today";
- echo "<br/>Time: $time <br/><br/>";
- $arr = array (
- array( 'Day' => 'Monday',
- 'Start' => '0830',
- 'End' => '1730',
- 'Site' => 'NW1'),
- array( 'Day' => 'Monday',
- 'Start' => '1200',
- 'End' => '1300',
- 'Site' => 'PL1'),
- array( 'Day' => 'Monday',
- 'Start' =>'1730',
- 'End' => '2130',
- 'Site' => 'RE1')
- );
- usort($arr, function($a, $b) {
- return (date("N", strtotime($a['Day'])) <=> date("N", strtotime($b['Day']))) * 100 +
- ($b['Start'] <=> $a['Start']) * 10 +
- ($a['End'] <=> $b['End']);
- });
- foreach ($arr as $i => $values) {
- if ($today != $values['Day']) continue;
- if ($time >= $values['Start'] && $time <= $values['End']) {
- $site = $values['Site'];
- break;
- }
- }
- echo "$today @ $time Site => $site";