timecard array tests - 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 timecard array tests.php

  1. <?php
  2. $timecards = [];
  3. array_push(
  4.     $timecards
  5.    ,
  6.     array('order_id' => 8638,
  7.     'work_date' => 1609650000,
  8.     'clock_in' => 1609650000,
  9.     'clock_out' => 1609650000,
  10.     'reg_hrs' => 0.00,
  11.     'facility' => 0,
  12.     'in_hr_min_txt' => '00:00',
  13.     'out_hr_min_txt' => '00:00',
  14.     'employer' => 327,
  15.     'week_start' => 1609650000
  16.     ),
  17.     array('order_id' => 8638,
  18.     'work_date' => 1609736400,
  19.     'clock_in' => 1609765200,
  20.     'clock_out' => 1609779600,
  21.     'reg_hrs' => 4.00,
  22.     'facility' => 503,
  23.     'in_hr_min_txt' => '08:00',
  24.     'out_hr_min_txt' => '12:00',
  25.     'employer' => 327,
  26.     'week_start' => 1609650000
  27.     ),
  28.     array('order_id' => 8638,
  29.     'work_date' => 1609736400,
  30.     'clock_in' => 1609781160,
  31.     'clock_out' => 1609788000,
  32.     'reg_hrs' => 1.90,
  33.     'facility' => 503,
  34.     'in_hr_min_txt' => '12:26',
  35.     'out_hr_min_txt' => '14:20',
  36.     'employer' => 327,
  37.     'week_start' => 1609650000
  38.     ),
  39.     array('order_id' => 8638,
  40.     'work_date' => 1609822800,
  41.     'clock_in' => 1609853400,
  42.     'clock_out' => 1609866000,
  43.     'reg_hrs' => 3.50,
  44.     'facility' => 503,
  45.     'in_hr_min_txt' => '08:30',
  46.     'out_hr_min_txt' => '12:00',
  47.     'employer' => 327,
  48.     'week_start' => 1609650000
  49.     ),
  50.     array('order_id' => 8638,
  51.     'work_date' => 1609822800,
  52.     'clock_in' => 1609867800,
  53.     'clock_out' => 1609882440,
  54.     'reg_hrs' => 4.07,
  55.     'facility' => 503,
  56.     'in_hr_min_txt' => '12:30',
  57.     'out_hr_min_txt' => '16:34',
  58.     'employer' => 327,
  59.     'week_start' => 1609650000
  60.     ),
  61.     array('order_id' => 8638,
  62.     'work_date' => 1609909200,
  63.     'clock_in' => 1609938300,
  64.     'clock_out' => 1609951860,
  65.     'reg_hrs' => 3.77,
  66.     'facility' => 503,
  67.     'in_hr_min_txt' => '08:05',
  68.     'out_hr_min_txt' => '11:51',
  69.     'employer' => 327,
  70.     'week_start' => 1609650000
  71.     ),
  72.     array('order_id' => 8638,
  73.     'work_date' => 1609909200,
  74.     'clock_in' => 1609954860,
  75.     'clock_out' => 1609964160,
  76.     'reg_hrs' => 2.58,
  77.     'facility' => 503,
  78.     'in_hr_min_txt' => '12:41',
  79.     'out_hr_min_txt' => '15:16',
  80.     'employer' => 327,
  81.     'week_start' => 1609650000
  82.     ),
  83.     array('order_id' => 8638,
  84.     'work_date' => 1609909200,
  85.     'clock_in' => 1609974180,
  86.     'clock_out' => 1609976640,
  87.     'reg_hrs' => 0.68,
  88.     'facility' => 503,
  89.     'in_hr_min_txt' => '18:03',
  90.     'out_hr_min_txt' => '18:44',
  91.     'employer' => 327,
  92.     'week_start' => 1609650000
  93.     ),
  94.     array('order_id' => 8638,
  95.     'work_date' => 1609995600,
  96.     'clock_in' => 1610026680,
  97.     'clock_out' => 1610040600,
  98.     'reg_hrs' => 3.87,
  99.     'facility' => 504,
  100.     'in_hr_min_txt' => '08:38',
  101.     'out_hr_min_txt' => '12:30',
  102.     'employer' => 327,
  103.     'week_start' => 1609650000
  104.     ),
  105.     array('order_id' => 8638,
  106.     'work_date' => 1609995600,
  107.     'clock_in' => 1610041860,
  108.     'clock_out' => 1610060580,
  109.     'reg_hrs' => 5.20,
  110.     'facility' => 503,
  111.     'in_hr_min_txt' => '12:51',
  112.     'out_hr_min_txt' => '18:03',
  113.     'employer' => 327,
  114.     'week_start' => 1609650000
  115.     ),
  116.     array('order_id' => 8638,
  117.     'work_date' => 1610082000,
  118.     'clock_in' => 1610110800,
  119.     'clock_out' => 1610117460,
  120.     'reg_hrs' => 1.85,
  121.     'facility' => 504,
  122.     'in_hr_min_txt' => '08:00',
  123.     'out_hr_min_txt' => '09:51',
  124.     'employer' => 327,
  125.     'week_start' => 1609650000
  126.     ),
  127.     array('order_id' => 8638,
  128.     'work_date' => 1610082000,
  129.     'clock_in' => 1610119500,
  130.     'clock_out' => 1610137020,
  131.     'reg_hrs' => 4.87,
  132.     'facility' => 503,
  133.     'in_hr_min_txt' => '10:25',
  134.     'out_hr_min_txt' => '15:17',
  135.     'employer' => 327,
  136.     'week_start' => 1609650000
  137.     ),
  138.     array('order_id' => 8638,
  139.     'work_date' => 1610168400,
  140.     'clock_in' => 1610200860,
  141.     'clock_out' => 1610212680,
  142.     'reg_hrs' => 3.28,
  143.     'facility' => 503,
  144.     'in_hr_min_txt' => '09:01',
  145.     'out_hr_min_txt' => '12:18',
  146.     'employer' => 327,
  147.     'week_start' => 1609650000
  148.     ),
  149.     array('order_id' => 8642,
  150.     'work_date' => 1609650000,
  151.     'clock_in' => 1609650000,
  152.     'clock_out' => 1609650000,
  153.     'reg_hrs' => 0.00,
  154.     'facility' => 0,
  155.     'in_hr_min_txt' => '00:00',
  156.     'out_hr_min_txt' => '00:00',
  157.     'employer' => 327,
  158.     'week_start' => 1609650000
  159.     ),
  160.     array('order_id' => 8642,
  161.     'work_date' => 1609736400,
  162.     'clock_in' => 1609766760,
  163.     'clock_out' => 1609783020,
  164.     'reg_hrs' => 4.52,
  165.     'facility' => 405,
  166.     'in_hr_min_txt' => '08:26',
  167.     'out_hr_min_txt' => '12:57',
  168.     'employer' => 327,
  169.     'week_start' => 1609650000
  170.     ),
  171.     array('order_id' => 8642,
  172.     'work_date' => 1609736400,
  173.     'clock_in' => 1609784520,
  174.     'clock_out' => 1609796880,
  175.     'reg_hrs' => 3.43,
  176.     'facility' => 405,
  177.     'in_hr_min_txt' => '13:22',
  178.     'out_hr_min_txt' => '16:48',
  179.     'employer' => 327,
  180.     'week_start' => 1609650000
  181.     ),
  182.     array('order_id' => 8642,
  183.     'work_date' => 1609822800,
  184.     'clock_in' => 1609850940,
  185.     'clock_out' => 1609869000,
  186.     'reg_hrs' => 5.02,
  187.     'facility' => 405,
  188.     'in_hr_min_txt' => '07:49',
  189.     'out_hr_min_txt' => '12:50',
  190.     'employer' => 327,
  191.     'week_start' => 1609650000
  192.     ),
  193.     array('order_id' => 8642,
  194.     'work_date' => 1609822800,
  195.     'clock_in' => 1609870680,
  196.     'clock_out' => 1609873800,
  197.     'reg_hrs' => 0.87,
  198.     'facility' => 405,
  199.     'in_hr_min_txt' => '13:18',
  200.     'out_hr_min_txt' => '14:10',
  201.     'employer' => 327,
  202.     'week_start' => 1609650000
  203.     ),
  204.     array('order_id' => 8642,
  205.     'work_date' => 1609909200,
  206.     'clock_in' => 1609940280,
  207.     'clock_out' => 1609956420,
  208.     'reg_hrs' => 4.48,
  209.     'facility' => 405,
  210.     'in_hr_min_txt' => '08:38',
  211.     'out_hr_min_txt' => '13:07',
  212.     'employer' => 327,
  213.     'week_start' => 1609650000
  214.     ),
  215.     array('order_id' => 8642,
  216.     'work_date' => 1609909200,
  217.     'clock_in' => 1609958100,
  218.     'clock_out' => 1609969260,
  219.     'reg_hrs' => 3.10,
  220.     'facility' => 405,
  221.     'in_hr_min_txt' => '13:35',
  222.     'out_hr_min_txt' => '16:41',
  223.     'employer' => 327,
  224.     'week_start' => 1609650000
  225.     ),
  226.     array('order_id' => 8642,
  227.     'work_date' => 1609995600,
  228.     'clock_in' => 1610025960,
  229.     'clock_out' => 1610040840,
  230.     'reg_hrs' => 4.13,
  231.     'facility' => 405,
  232.     'in_hr_min_txt' => '08:26',
  233.     'out_hr_min_txt' => '12:34',
  234.     'employer' => 327,
  235.     'week_start' => 1609650000
  236.     ),
  237.     array('order_id' => 8642,
  238.     'work_date' => 1609995600,
  239.     'clock_in' => 1610042820,
  240.     'clock_out' => 1610050380,
  241.     'reg_hrs' => 2.10,
  242.     'facility' => 405,
  243.     'in_hr_min_txt' => '13:07',
  244.     'out_hr_min_txt' => '15:13',
  245.     'employer' => 327,
  246.     'week_start' => 1609650000
  247.     ),
  248.     array('order_id' => 8642,
  249.     'work_date' => 1610082000,
  250.     'clock_in' => 1610082000,
  251.     'clock_out' => 1610082000,
  252.     'reg_hrs' => 0.00,
  253.     'facility' => 0,
  254.     'in_hr_min_txt' => '00:00',
  255.     'out_hr_min_txt' => '00:00',
  256.     'employer' => 327,
  257.     'week_start' => 1609650000
  258.     ),
  259.     array('order_id' => 8642,
  260.     'work_date' => 1610168400,
  261.     'clock_in' => 1610200320,
  262.     'clock_out' => 1610214360,
  263.     'reg_hrs' => 3.90,
  264.     'facility' => 405,
  265.     'in_hr_min_txt' => '08:52',
  266.     'out_hr_min_txt' => '12:46',
  267.     'employer' => 327,
  268.     'week_start' => 1609650000
  269.     ),
  270.     array('order_id' => 8642,
  271.     'work_date' => 1610168400,
  272.     'clock_in' => 1610215560,
  273.     'clock_out' => 1610228760,
  274.     'reg_hrs' => 3.67,
  275.     'facility' => 405,
  276.     'in_hr_min_txt' => '13:06',
  277.     'out_hr_min_txt' => '16:46',
  278.     'employer' => 327,
  279.     'week_start' => 1609650000
  280.     ),
  281.     array('order_id' => 8647,
  282.     'work_date' => 1609650000,
  283.     'clock_in' => 1609650000,
  284.     'clock_out' => 1609650000,
  285.     'reg_hrs' => 0.00,
  286.     'facility' => 0,
  287.     'in_hr_min_txt' => '00:00',
  288.     'out_hr_min_txt' => '00:00',
  289.     'employer' => 327,
  290.     'week_start' => 1609650000
  291.     ),
  292.     array('order_id' => 8647,
  293.     'work_date' => 1609736400,
  294.     'clock_in' => 1609788600,
  295.     'clock_out' => 1609793640,
  296.     'reg_hrs' => 1.40,
  297.     'facility' => 504,
  298.     'in_hr_min_txt' => '14:30',
  299.     'out_hr_min_txt' => '15:54',
  300.     'employer' => 327,
  301.     'week_start' => 1609650000
  302.     ),
  303.     array('order_id' => 8647,
  304.     'work_date' => 1609822800,
  305.     'clock_in' => 1609874040,
  306.     'clock_out' => 1609878960,
  307.     'reg_hrs' => 1.37,
  308.     'facility' => 504,
  309.     'in_hr_min_txt' => '14:14',
  310.     'out_hr_min_txt' => '15:36',
  311.     'employer' => 327,
  312.     'week_start' => 1609650000
  313.     ),
  314.     array('order_id' => 8647,
  315.     'work_date' => 1609909200,
  316.     'clock_in' => 1609909200,
  317.     'clock_out' => 1609909200,
  318.     'reg_hrs' => 0.00,
  319.     'facility' => 0,
  320.     'in_hr_min_txt' => '00:00',
  321.     'out_hr_min_txt' => '00:00',
  322.     'employer' => 327,
  323.     'week_start' => 1609650000
  324.     ),
  325.     array('order_id' => 8647,
  326.     'work_date' => 1609995600,
  327.     'clock_in' => 1610048160,
  328.     'clock_out' => 1610052300,
  329.     'reg_hrs' => 1.15,
  330.     'facility' => 504,
  331.     'in_hr_min_txt' => '14:36',
  332.     'out_hr_min_txt' => '15:45',
  333.     'employer' => 327,
  334.     'week_start' => 1609650000
  335.     ),
  336.     array('order_id' => 8647,
  337.     'work_date' => 1610082000,
  338.     'clock_in' => 1610082000,
  339.     'clock_out' => 1610082000,
  340.     'reg_hrs' => 0.00,
  341.     'facility' => 0,
  342.     'in_hr_min_txt' => '00:00',
  343.     'out_hr_min_txt' => '00:00',
  344.     'employer' => 327,
  345.     'week_start' => 1609650000
  346.     ),
  347.     array('order_id' => 8647,
  348.     'work_date' => 1610168400,
  349.     'clock_in' => 1610196540,
  350.     'clock_out' => 1610200140,
  351.     'reg_hrs' => 1.00,
  352.     'facility' => 504,
  353.     'in_hr_min_txt' => '07:49',
  354.     'out_hr_min_txt' => '08:49',
  355.     'employer' => 327,
  356.     'week_start' => 1609650000
  357.     ),
  358.     array('order_id' => 8651,
  359.     'work_date' => 1609650000,
  360.     'clock_in' => 1609650000,
  361.     'clock_out' => 1609650000,
  362.     'reg_hrs' => 0.00,
  363.     'facility' => 0,
  364.     'in_hr_min_txt' => '00:00',
  365.     'out_hr_min_txt' => '00:00',
  366.     'employer' => 327,
  367.     'week_start' => 1609650000
  368.     ),
  369.     array('order_id' => 8651,
  370.     'work_date' => 1609736400,
  371.     'clock_in' => 1609772100,
  372.     'clock_out' => 1609785420,
  373.     'reg_hrs' => 3.70,
  374.     'facility' => 501,
  375.     'in_hr_min_txt' => '09:55',
  376.     'out_hr_min_txt' => '13:37',
  377.     'employer' => 327,
  378.     'week_start' => 1609650000
  379.     ),
  380.     array('order_id' => 8651,
  381.     'work_date' => 1609736400,
  382.     'clock_in' => 1609786440,
  383.     'clock_out' => 1609797660,
  384.     'reg_hrs' => 3.12,
  385.     'facility' => 501,
  386.     'in_hr_min_txt' => '13:54',
  387.     'out_hr_min_txt' => '17:01',
  388.     'employer' => 327,
  389.     'week_start' => 1609650000
  390.     ),
  391.     array('order_id' => 8651,
  392.     'work_date' => 1609822800,
  393.     'clock_in' => 1609854540,
  394.     'clock_out' => 1609868760,
  395.     'reg_hrs' => 3.95,
  396.     'facility' => 501,
  397.     'in_hr_min_txt' => '08:49',
  398.     'out_hr_min_txt' => '12:46',
  399.     'employer' => 327,
  400.     'week_start' => 1609650000
  401.     ),
  402.     array('order_id' => 8651,
  403.     'work_date' => 1609822800,
  404.     'clock_in' => 1609870620,
  405.     'clock_out' => 1609879560,
  406.     'reg_hrs' => 2.48,
  407.     'facility' => 501,
  408.     'in_hr_min_txt' => '13:17',
  409.     'out_hr_min_txt' => '15:46',
  410.     'employer' => 327,
  411.     'week_start' => 1609650000
  412.     ),
  413.     array('order_id' => 8651,
  414.     'work_date' => 1609909200,
  415.     'clock_in' => 1609942020,
  416.     'clock_out' => 1609954980,
  417.     'reg_hrs' => 3.60,
  418.     'facility' => 501,
  419.     'in_hr_min_txt' => '09:07',
  420.     'out_hr_min_txt' => '12:43',
  421.     'employer' => 327,
  422.     'week_start' => 1609650000
  423.     ),
  424.     array('order_id' => 8651,
  425.     'work_date' => 1609909200,
  426.     'clock_in' => 1609958580,
  427.     'clock_out' => 1609965300,
  428.     'reg_hrs' => 1.87,
  429.     'facility' => 501,
  430.     'in_hr_min_txt' => '13:43',
  431.     'out_hr_min_txt' => '15:35',
  432.     'employer' => 327,
  433.     'week_start' => 1609650000
  434.     ),
  435.     array('order_id' => 8651,
  436.     'work_date' => 1609995600,
  437.     'clock_in' => 1610027880,
  438.     'clock_out' => 1610043060,
  439.     'reg_hrs' => 4.22,
  440.     'facility' => 501,
  441.     'in_hr_min_txt' => '08:58',
  442.     'out_hr_min_txt' => '13:11',
  443.     'employer' => 327,
  444.     'week_start' => 1609650000
  445.     ),
  446.     array('order_id' => 8651,
  447.     'work_date' => 1609995600,
  448.     'clock_in' => 1610045220,
  449.     'clock_out' => 1610054340,
  450.     'reg_hrs' => 2.53,
  451.     'facility' => 501,
  452.     'in_hr_min_txt' => '13:47',
  453.     'out_hr_min_txt' => '16:19',
  454.     'employer' => 327,
  455.     'week_start' => 1609650000
  456.     ),
  457.     array('order_id' => 8651,
  458.     'work_date' => 1610082000,
  459.     'clock_in' => 1610082000,
  460.     'clock_out' => 1610082000,
  461.     'reg_hrs' => 0.00,
  462.     'facility' => 0,
  463.     'in_hr_min_txt' => '00:00',
  464.     'out_hr_min_txt' => '00:00',
  465.     'employer' => 327,
  466.     'week_start' => 1609650000
  467.     ),
  468.     array('order_id' => 8651,
  469.     'work_date' => 1610168400,
  470.     'clock_in' => 1610168400,
  471.     'clock_out' => 1610168400,
  472.     'reg_hrs' => 0.00,
  473.     'facility' => 0,
  474.     'in_hr_min_txt' => '00:00',
  475.     'out_hr_min_txt' => '00:00',
  476.     'employer' => 327,
  477.     'week_start' => 1609650000
  478.     ) 
  479. );
  480.  
  481. $jobcandarr = [];
  482. array_push(
  483.     $jobcandarr
  484.     ,array
  485.     ('order_id' => 8638,
  486.     'candidate_id' => 55915,
  487.     'bid_amt' => 40.00,
  488.     'ot_rate' => 1.50,
  489.     'holiday_rate' => 1.00,
  490.     'mem_group' => 105,
  491.     'contract_fee' => 0.0250,
  492.     'primary_facility' => 1
  493.     ),
  494.     array('order_id' => 8642,
  495.     'candidate_id' => 58072,
  496.     'bid_amt' => 38.00,
  497.     'ot_rate' => 1.50,
  498.     'holiday_rate' => 1.00,
  499.     'mem_group' => 111,
  500.     'contract_fee' => 0.0250,
  501.     'primary_facility' => 24
  502.     ),
  503.     array('order_id' => 8647,
  504.     'candidate_id' => 59728,
  505.     'bid_amt' => 70.00,
  506.     'ot_rate' => 1.50,
  507.     'holiday_rate' => 1.00,
  508.     'mem_group' => 389,
  509.     'contract_fee' => 0.0250,
  510.     'primary_facility' => 4
  511.     ),
  512.     array('order_id' => 8651,
  513.     'candidate_id' => 59761,
  514.     'bid_amt' => 60.00,
  515.     'ot_rate' => 1.50,
  516.     'holiday_rate' => 1.00,
  517.     'mem_group' => 105,
  518.     'contract_fee' => 0.0250,
  519.     'primary_facility' => 2)
  520. );
  521.  
  522. $newarr = [];
  523. $i=0;
  524. foreach ($timecards as $key1 => $subkey) {
  525.     $prevorder = 0;
  526.     foreach ($subkey as $key => $timeorder) {
  527.         if ($key === 'order_id') {
  528.             $jobcandorder = array_search($timeorder, array_column($jobcandarr[$i]['order_id'], 'order_id'));
  529.             echo " timeorede=" . $timeorder . ' and jobcandorder=' . $jobcandorder;
  530.             if ( $timeorder == $jobcandorder)  {
  531.                 $newarr[] = $subkey + $jobcandarr;
  532.              //   echo "),<br> (";
  533.             //    $prevorder = $value;
  534.             }
  535.         }
  536.       //  echo "'" . $key . "' => ";
  537.       //  if ($key === 'in_hr_min_txt' || $key === 'out_hr_min_txt') {
  538.       //      echo "'" . $value . "', " . "<br>";
  539.      //   }else{
  540.      //       echo $value . ", " . "<br>";
  541.      //   }
  542.     }
  543.     $i++;
  544. };
  545. print_r($newarr);
File Description
  • timecard array tests
  • PHP Code
  • 12 Feb-2021
  • 14.11 Kb
You can Share it: