3v4l.org

run code in 500+ PHP versions simultaneously
<?php $counts = [ "900,google.com", "60,mail.yahoo.com", "10,mobile.sports.yahoo.com", "40,sports.yahoo.com", "300,yahoo.com", "10,stackoverflow.com", "20,overflow.com", "5,com.com", "2,en.wikipedia.org", "1,m.wikipedia.org", "1,mobile.sports", "1,google.co.uk" ]; function calculateClicksByDomain($dataLines) { $output = []; foreach ($dataLines as $dataLine) { [$count, $domain] = explode(',', $dataLine); $nameParts = []; foreach (array_reverse(explode('.', $domain)) as $namePart) { array_unshift($nameParts, $namePart); $domain = implode('.', $nameParts); $output[$domain] = ($output[$domain] ?? 0) + $count; } } return $output; } print_r(calculateClicksByDomain($counts));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o5VgJ
function name:  (null)
number of ops:  8
compiled vars:  !0 = $counts
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   33     1        INIT_FCALL                                                   'print_r'
          2        INIT_FCALL                                                   'calculateclicksbydomain'
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $2      
          5        SEND_VAR                                                     $2
          6        DO_ICALL                                                     
          7      > RETURN                                                       1

Function calculateclicksbydomain:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 38
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 38
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 36
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 36
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 36
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/o5VgJ
function name:  calculateClicksByDomain
number of ops:  41
compiled vars:  !0 = $dataLines, !1 = $output, !2 = $dataLine, !3 = $count, !4 = $domain, !5 = $nameParts, !6 = $namePart
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV                                                 !0      
   20     1        ASSIGN                                                       !1, <array>
   21     2      > FE_RESET_R                                           $8      !0, ->38
          3    > > FE_FETCH_R                                                   $8, !2, ->38
   22     4    >   INIT_FCALL                                                   'explode'
          5        SEND_VAL                                                     '%2C'
          6        SEND_VAR                                                     !2
          7        DO_ICALL                                             $9      
          8        FETCH_LIST_R                                         $10     $9, 0
          9        ASSIGN                                                       !3, $10
         10        FETCH_LIST_R                                         $12     $9, 1
         11        ASSIGN                                                       !4, $12
         12        FREE                                                         $9
   23    13        ASSIGN                                                       !5, <array>
   24    14        INIT_FCALL                                                   'array_reverse'
         15        INIT_FCALL                                                   'explode'
         16        SEND_VAL                                                     '.'
         17        SEND_VAR                                                     !4
         18        DO_ICALL                                             $15     
         19        SEND_VAR                                                     $15
         20        DO_ICALL                                             $16     
         21      > FE_RESET_R                                           $17     $16, ->36
         22    > > FE_FETCH_R                                                   $17, !6, ->36
   25    23    >   INIT_FCALL                                                   'array_unshift'
         24        SEND_REF                                                     !5
         25        SEND_VAR                                                     !6
         26        DO_ICALL                                                     
   26    27        FRAMELESS_ICALL_2                implode             ~19     '.', !5
         28        ASSIGN                                                       !4, ~19
   27    29        FETCH_DIM_IS                                         ~22     !1, !4
         30        COALESCE                                             ~23     ~22
         31        QM_ASSIGN                                            ~23     0
         32        ADD                                                  ~24     ~23, !3
         33        ASSIGN_DIM                                                   !1, !4
         34        OP_DATA                                                      ~24
   24    35      > JMP                                                          ->22
         36    >   FE_FREE                                                      $17
   21    37      > JMP                                                          ->3
         38    >   FE_FREE                                                      $8
   30    39      > RETURN                                                       !1
   31    40*     > RETURN                                                       null

End of function calculateclicksbydomain

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
168.78 ms | 1537 KiB | 18 Q