3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generateAffiliateCommands(int $companyId, int $daysBack) { $sections = [ 'AFFILIATES' => [ "affiliate:cac-sync-affiliates %d", "affiliate:cac-sync-commission-plan-reports %d" ], 'COMMISSIONS' => [ "affiliate:cac-sync-commissions %d --dateFrom=\\\"%s\\\" --dateTo=\\\"%s\\\"" ], 'REGISTRATIONS' => [ "affiliate:cac-sync-registrations %d --dateFrom=\\\"%s\\\" --dateTo=\\\"%s\\\"" ], 'TRANSACTIONS' => [ "affiliate:cac-sync-transactions %d --dateFrom=\\\"%s\\\" --dateTo=\\\"%s\\\"" ] ]; $commands = []; // AFFILIATES section $commands[] = "## AFFILIATES ##"; $affiliateCmds = []; foreach ($sections['AFFILIATES'] as $index => $cmd) { $formatted = sprintf($cmd, $companyId); if ($index > 0) { $formatted = "php artisan $formatted"; } $affiliateCmds[] = $formatted; } $commands[] = implode(' && ', $affiliateCmds); // Generate 30-day periods starting from -1 backwards $periods = []; $chunkSize = 30; $currentTo = -1; while (abs($currentTo) < $daysBack) { $currentFrom = $currentTo - $chunkSize + 1; // Ensure we don’t go beyond -daysBack if (abs($currentFrom) > $daysBack) { $currentFrom = -$daysBack; } $periods[] = [$currentFrom, $currentTo]; // Next chunk ends where this one starts $currentTo = $currentFrom - 1; } // Flip to oldest first (-daysBack → -1) $periods = array_reverse($periods); // Generate other sections foreach (['COMMISSIONS', 'REGISTRATIONS', 'TRANSACTIONS'] as $section) { $commands[] = "## $section ##"; $sectionCmds = []; foreach ($periods as $i => [$from, $to]) { if ($to !== -1) { $to = $to + 1; } $cmd = sprintf($sections[$section][0], $companyId, "$from days", "$to days"); if ($i > 0) { $cmd = "php artisan $cmd"; } $sectionCmds[] = $cmd; } $commands[] = implode(' && ', $sectionCmds); } return implode("\n\n", $commands); } function dateToDaysAgo(string $date) { // Create DateTime objects $given = new DateTime($date); $now = new DateTime(); // current date and time // Calculate difference $diff = $now->diff($given); // Total days difference $daysAgo = $diff->days; // If the given date is in the past, return negative if ($given < $now) { return $daysAgo + 1; } else { return -$daysAgo - 1; } } $companyId = 223; $date = '2023-11-13 15:44:50'; echo generateAffiliateCommands($companyId, dateToDaysAgo($date));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VZ8Jq
function name:  (null)
number of ops:  11
compiled vars:  !0 = $companyId, !1 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   ASSIGN                                                   !0, 223
   97     1        ASSIGN                                                   !1, '2023-11-13+15%3A44%3A50'
   99     2        INIT_FCALL                                               'generateaffiliatecommands'
          3        SEND_VAR                                                 !0
          4        INIT_FCALL                                               'datetodaysago'
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_FCALL                                      0  $5      
          9        ECHO                                                     $5
         10      > RETURN                                                   1

Function generateaffiliatecommands:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 24
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 21
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 35
Branch analysis from position: 56
2 jumps found. (Code = 77) Position 1 = 61, Position 2 = 109
Branch analysis from position: 61
2 jumps found. (Code = 78) Position 1 = 62, Position 2 = 109
Branch analysis from position: 62
2 jumps found. (Code = 77) Position 1 = 69, Position 2 = 101
Branch analysis from position: 69
2 jumps found. (Code = 78) Position 1 = 70, Position 2 = 101
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 98
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
Branch analysis from position: 98
Branch analysis from position: 80
Branch analysis from position: 101
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 101
Branch analysis from position: 109
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 109
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 35
Branch analysis from position: 56
Branch analysis from position: 35
Branch analysis from position: 45
Branch analysis from position: 24
filename:       /in/VZ8Jq
function name:  generateAffiliateCommands
number of ops:  116
compiled vars:  !0 = $companyId, !1 = $daysBack, !2 = $sections, !3 = $commands, !4 = $affiliateCmds, !5 = $cmd, !6 = $index, !7 = $formatted, !8 = $periods, !9 = $chunkSize, !10 = $currentTo, !11 = $currentFrom, !12 = $section, !13 = $sectionCmds, !14 = $from, !15 = $to, !16 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
   20     3        ASSIGN                                                   !3, <array>
   23     4        ASSIGN_DIM                                               !3
          5        OP_DATA                                                  '%23%23+AFFILIATES+%23%23'
   24     6        ASSIGN                                                   !4, <array>
   25     7        FETCH_DIM_R                                      ~21     !2, 'AFFILIATES'
          8      > FE_RESET_R                                       $22     ~21, ->24
          9    > > FE_FETCH_R                                       ~23     $22, !5, ->24
         10    >   ASSIGN                                                   !6, ~23
   26    11        INIT_FCALL                                               'sprintf'
         12        SEND_VAR                                                 !5
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $25     
         15        ASSIGN                                                   !7, $25
   27    16        IS_SMALLER                                               0, !6
         17      > JMPZ                                                     ~27, ->21
   28    18    >   NOP                                                      
         19        FAST_CONCAT                                      ~28     'php+artisan+', !7
         20        ASSIGN                                                   !7, ~28
   30    21    >   ASSIGN_DIM                                               !4
         22        OP_DATA                                                  !7
   25    23      > JMP                                                      ->9
         24    >   FE_FREE                                                  $22
   32    25        INIT_FCALL                                               'implode'
         26        SEND_VAL                                                 '+%26%26+'
         27        SEND_VAR                                                 !4
         28        DO_ICALL                                         $32     
         29        ASSIGN_DIM                                               !3
         30        OP_DATA                                                  $32
   35    31        ASSIGN                                                   !8, <array>
   36    32        ASSIGN                                                   !9, 30
   37    33        ASSIGN                                                   !10, -1
   39    34      > JMP                                                      ->51
   40    35    >   SUB                                              ~36     !10, !9
         36        ADD                                              ~37     ~36, 1
         37        ASSIGN                                                   !11, ~37
   43    38        INIT_FCALL                                               'abs'
         39        SEND_VAR                                                 !11
         40        DO_ICALL                                         $39     
         41        IS_SMALLER                                               !1, $39
         42      > JMPZ                                                     ~40, ->45
   44    43    >   MUL                                              ~41     !1, -1
         44        ASSIGN                                                   !11, ~41
   47    45    >   INIT_ARRAY                                       ~44     !11
         46        ADD_ARRAY_ELEMENT                                ~44     !10
         47        ASSIGN_DIM                                               !8
         48        OP_DATA                                                  ~44
   50    49        SUB                                              ~45     !11, 1
         50        ASSIGN                                                   !10, ~45
   39    51    >   INIT_FCALL                                               'abs'
         52        SEND_VAR                                                 !10
         53        DO_ICALL                                         $47     
         54        IS_SMALLER                                               $47, !1
         55      > JMPNZ                                                    ~48, ->35
   54    56    >   INIT_FCALL                                               'array_reverse'
         57        SEND_VAR                                                 !8
         58        DO_ICALL                                         $49     
         59        ASSIGN                                                   !8, $49
   57    60      > FE_RESET_R                                       $51     <array>, ->109
         61    > > FE_FETCH_R                                               $51, !12, ->109
   58    62    >   ROPE_INIT                                     3  ~54     '%23%23+'
         63        ROPE_ADD                                      1  ~54     ~54, !12
         64        ROPE_END                                      2  ~53     ~54, '+%23%23'
         65        ASSIGN_DIM                                               !3
         66        OP_DATA                                                  ~53
   59    67        ASSIGN                                                   !13, <array>
   60    68      > FE_RESET_R                                       $57     !8, ->101
         69    > > FE_FETCH_R                                       ~63     $57, $58, ->101
         70    >   FETCH_LIST_R                                     $59     $58, 0
         71        ASSIGN                                                   !14, $59
         72        FETCH_LIST_R                                     $61     $58, 1
         73        ASSIGN                                                   !15, $61
         74        FREE                                                     $58
         75        ASSIGN                                                   !16, ~63
   61    76        IS_NOT_IDENTICAL                                         !15, -1
         77      > JMPZ                                                     ~65, ->80
   62    78    >   ADD                                              ~66     !15, 1
         79        ASSIGN                                                   !15, ~66
   65    80    >   INIT_FCALL                                               'sprintf'
         81        FETCH_DIM_R                                      ~68     !2, !12
         82        FETCH_DIM_R                                      ~69     ~68, 0
         83        SEND_VAL                                                 ~69
         84        SEND_VAR                                                 !0
         85        NOP                                                      
         86        FAST_CONCAT                                      ~70     !14, '+days'
         87        SEND_VAL                                                 ~70
         88        NOP                                                      
         89        FAST_CONCAT                                      ~71     !15, '+days'
         90        SEND_VAL                                                 ~71
         91        DO_ICALL                                         $72     
         92        ASSIGN                                                   !5, $72
   66    93        IS_SMALLER                                               0, !16
         94      > JMPZ                                                     ~74, ->98
   67    95    >   NOP                                                      
         96        FAST_CONCAT                                      ~75     'php+artisan+', !5
         97        ASSIGN                                                   !5, ~75
   69    98    >   ASSIGN_DIM                                               !13
         99        OP_DATA                                                  !5
   60   100      > JMP                                                      ->69
        101    >   FE_FREE                                                  $57
   71   102        INIT_FCALL                                               'implode'
        103        SEND_VAL                                                 '+%26%26+'
        104        SEND_VAR                                                 !13
        105        DO_ICALL                                         $79     
        106        ASSIGN_DIM                                               !3
        107        OP_DATA                                                  $79
   57   108      > JMP                                                      ->61
        109    >   FE_FREE                                                  $51
   74   110        INIT_FCALL                                               'implode'
        111        SEND_VAL                                                 '%0A%0A'
        112        SEND_VAR                                                 !3
        113        DO_ICALL                                         $80     
        114      > RETURN                                                   $80
   75   115*     > RETURN                                                   null

End of function generateaffiliatecommands

Function datetodaysago:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VZ8Jq
function name:  dateToDaysAgo
number of ops:  23
compiled vars:  !0 = $date, !1 = $given, !2 = $now, !3 = $diff, !4 = $daysAgo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
   79     1        NEW                                              $5      'DateTime'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $5
   80     5        NEW                                              $8      'DateTime'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $8
   83     8        INIT_METHOD_CALL                                         !2, 'diff'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0  $11     
         11        ASSIGN                                                   !3, $11
   86    12        FETCH_OBJ_R                                      ~13     !3, 'days'
         13        ASSIGN                                                   !4, ~13
   89    14        IS_SMALLER                                               !1, !2
         15      > JMPZ                                                     ~15, ->19
   90    16    >   ADD                                              ~16     !4, 1
         17      > RETURN                                                   ~16
   89    18*       JMP                                                      ->22
   92    19    >   MUL                                              ~17     !4, -1
         20        SUB                                              ~18     ~17, 1
         21      > RETURN                                                   ~18
   94    22*     > RETURN                                                   null

End of function datetodaysago

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.53 ms | 1032 KiB | 19 Q