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.



Your result can be seen below.

Result of php executing





Full code of 58998146.php

  1. <?php
  2.  
  3. $today = 'Monday'; // Full day name
  4. $time = '1205';
  5.  
  6. echo "<br/>Day: $today";
  7. echo "<br/>Time: $time <br/><br/>";
  8.  
  9.  
  10. $arr = array (
  11.     array(  'Day' => 'Monday',
  12.             'Start' => '0830',
  13.             'End' => '1730',
  14.             'Site' => 'NW1'),
  15.  
  16.     array(  'Day' => 'Monday',
  17.             'Start' => '1200',
  18.             'End' => '1300',
  19.             'Site' => 'PL1'),
  20.  
  21.     array(  'Day' => 'Monday',
  22.             'Start' =>'1730',
  23.             'End' => '2130',
  24.             'Site' => 'RE1')
  25. );
  26.  
  27. usort($arr, function($a, $b) {
  28.     return (date("N", strtotime($a['Day'])) <=> date("N", strtotime($b['Day']))) * 100 +
  29.            ($b['Start'] <=> $a['Start']) * 10 +
  30.            ($a['End'] <=> $b['End']);
  31. });
  32.  
  33. foreach ($arr as $i => $values) {
  34.     if ($today != $values['Day']) continue;
  35.  
  36.     if ($time >= $values['Start'] && $time <= $values['End']) {
  37.         $site = $values['Site'];
  38.         break;
  39.     }
  40. }
  41.  
  42. echo "$today @ $time Site => $site";
  43.  
File Description
  • 58998146
  • PHP Code
  • 22 Nov-2019
  • 953 Bytes
You can Share it: