3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Mock function to generate some random sales data, sometimes returning nothing. function getLocationSalesForDate(DateTime $date, string $location) { // Your business logic goes here. // Get the date as a string using DateTime::format(). // Return a random mock value for this demo. Will randomly return NULL so as to simulate // your table view. return (mt_rand(0, 3) === 1)?NULL:mt_rand(15, 70); } $locations = ['city 1', 'city 2', 'city 3', 'city 4', 'city 5', 'city 6']; $numColumns = 3; $dateStart = new DateTime; // 'P7D' means a period ('P') of 7 ('7') days ('D') from $dateStart. Consult the documentation of DateInterval's constructor for details. $dateEnd = (clone $dateStart)->add(new DateInterval('P7D')); // Segment your locations to however many you want to show on a single line. foreach (array_chunk($locations, $numColumns) as $columnHeadings) { // Output table haeding for this group of locations. $html = <<<EOT <table> <thead> <tr> <th>Date</th> EOT; // Write out each location as a column heading. foreach ($columnHeadings as $columnHeading) $html .= <<<EOT <th>$columnHeading</th> EOT; $html .= <<<EOT </tr> </thead> EOT; // Output sales per day for this location. $html .= <<<EOT <tbody> EOT; // Loop through each day between $dateStart and $dateEnd. $dateIterator = clone $dateStart; while ($dateIterator != $dateEnd) { // Start new row, print date on first column. $html .= <<<EOT <tr> <td>{$dateIterator->format('Y-m-d')}</td> EOT; // Loop through this segment's locations and fetch sales for this day. foreach ($columnHeadings as $location) { // Retrieve mock sales data for this day on this location. $sales = getLocationSalesForDate($dateIterator, $location); // Record sales if we have any. if ($sales) // Have sales. $html .= <<<EOT <td>$sales</td> EOT; else // No sales for this day. $html .= <<<EOT <td><!-- Empty cell if no sales recorded for this location on this day. --></td> EOT; } // Close sales data row. $html .= <<<EOT </tr> EOT; // Advance to next day for this location. $dateIterator->add(new DateInterval('P1D')); } // Close table for this location group. $html .= <<<EOT </tbody> </table> EOT; // Output table to user. echo $html; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 68
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 68
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 33
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 55
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 55
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 53
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 33
Branch analysis from position: 65
Branch analysis from position: 33
Branch analysis from position: 55
Branch analysis from position: 27
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
filename:       /in/bkpsY
function name:  (null)
number of ops:  70
compiled vars:  !0 = $locations, !1 = $numColumns, !2 = $dateStart, !3 = $dateEnd, !4 = $columnHeadings, !5 = $html, !6 = $columnHeading, !7 = $dateIterator, !8 = $location, !9 = $sales
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                       !0, <array>
   15     1        ASSIGN                                                       !1, 3
   17     2        NEW                                                  $12     'DateTime'
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !2, $12
   19     5        CLONE                                                ~15     !2
          6        INIT_METHOD_CALL                                             ~15, 'add'
          7        NEW                                                  $16     'DateInterval'
          8        SEND_VAL_EX                                                  'P7D'
          9        DO_FCALL                                          0          
         10        SEND_VAR_NO_REF_EX                                           $16
         11        DO_FCALL                                          0  $18     
         12        ASSIGN                                                       !3, $18
   22    13        INIT_FCALL                                                   'array_chunk'
         14        SEND_VAR                                                     !0
         15        SEND_VAR                                                     !1
         16        DO_ICALL                                             $20     
         17      > FE_RESET_R                                           $21     $20, ->68
         18    > > FE_FETCH_R                                                   $21, !4, ->68
   25    19    >   ASSIGN                                                       !5, '%3Ctable%3E%0A++++%3Cthead%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Cth%3EDate%3C%2Fth%3E%0A'
   34    20      > FE_RESET_R                                           $23     !4, ->27
         21    > > FE_FETCH_R                                                   $23, !6, ->27
   36    22    >   ROPE_INIT                                         3  ~25     '++++++++++++%3Cth%3E'
         23        ROPE_ADD                                          1  ~25     ~25, !6
         24        ROPE_END                                          2  ~24     ~25, '%3C%2Fth%3E%0A'
         25        ASSIGN_OP                                         8          !5, ~24
   34    26      > JMP                                                          ->21
         27    >   FE_FREE                                                      $23
   41    28        ASSIGN_OP                                         8          !5, '++++++++%3C%2Ftr%3E%0A++++%3C%2Fthead%3E%0A'
   48    29        ASSIGN_OP                                         8          !5, '++++%3Ctbody%3E%0A'
   53    30        CLONE                                                ~30     !2
         31        ASSIGN                                                       !7, ~30
   54    32      > JMP                                                          ->63
   58    33    >   ROPE_INIT                                         3  ~34     '++++++++%3Ctr%3E%0A++++++++++++%3Ctd%3E'
   59    34        INIT_METHOD_CALL                                             !7, 'format'
         35        SEND_VAL_EX                                                  'Y-m-d'
         36        DO_FCALL                                          0  $32     
         37        ROPE_ADD                                          1  ~34     ~34, $32
         38        ROPE_END                                          2  ~33     ~34, '%3C%2Ftd%3E%0A'
         39        ASSIGN_OP                                         8          !5, ~33
   64    40      > FE_RESET_R                                           $37     !4, ->55
         41    > > FE_FETCH_R                                                   $37, !8, ->55
   67    42    >   INIT_FCALL                                                   'getlocationsalesfordate'
         43        SEND_VAR                                                     !7
         44        SEND_VAR                                                     !8
         45        DO_FCALL                                          0  $38     
         46        ASSIGN                                                       !9, $38
   70    47      > JMPZ                                                         !9, ->53
   73    48    >   ROPE_INIT                                         3  ~41     '++++++++++++%3Ctd%3E'
         49        ROPE_ADD                                          1  ~41     ~41, !9
         50        ROPE_END                                          2  ~40     ~41, '%3C%2Ftd%3E%0A'
         51        ASSIGN_OP                                         8          !5, ~40
   70    52      > JMP                                                          ->54
   79    53    >   ASSIGN_OP                                         8          !5, '++++++++++++%3Ctd%3E%3C%21--+Empty+cell+if+no+sales+recorded+for+this+location+on+this+day.+--%3E%3C%2Ftd%3E%0A'
   64    54    > > JMP                                                          ->41
         55    >   FE_FREE                                                      $37
   86    56        ASSIGN_OP                                         8          !5, '++++++++%3C%2Ftr%3E%0A'
   91    57        INIT_METHOD_CALL                                             !7, 'add'
         58        NEW                                                  $46     'DateInterval'
         59        SEND_VAL_EX                                                  'P1D'
         60        DO_FCALL                                          0          
         61        SEND_VAR_NO_REF_EX                                           $46
         62        DO_FCALL                                          0          
   54    63    >   IS_NOT_EQUAL                                                 !7, !3
         64      > JMPNZ                                                        ~49, ->33
   96    65    >   ASSIGN_OP                                         8          !5, '++++%3C%2Ftbody%3E%0A%3C%2Ftable%3E%0A'
  102    66        ECHO                                                         !5
   22    67      > JMP                                                          ->18
         68    >   FE_FREE                                                      $21
  103    69      > RETURN                                                       1

Function getlocationsalesfordate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bkpsY
function name:  getLocationSalesForDate
number of ops:  17
compiled vars:  !0 = $date, !1 = $location
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   11     2        INIT_FCALL                                                   'mt_rand'
          3        SEND_VAL                                                     0
          4        SEND_VAL                                                     3
          5        DO_ICALL                                             $2      
          6        IS_IDENTICAL                                                 $2, 1
          7      > JMPZ                                                         ~3, ->10
          8    >   QM_ASSIGN                                            ~4      null
          9      > JMP                                                          ->15
         10    >   INIT_FCALL                                                   'mt_rand'
         11        SEND_VAL                                                     15
         12        SEND_VAL                                                     70
         13        DO_ICALL                                             $5      
         14        QM_ASSIGN                                            ~4      $5
         15    > > RETURN                                                       ~4
   12    16*     > RETURN                                                       null

End of function getlocationsalesfordate

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.15 ms | 1647 KiB | 16 Q