3v4l.org

run code in 500+ PHP versions simultaneously
<?php $a = array( '192.168.11.12/24', '62.10.11.12/32', '128.10.11.12/8', '96.50.51.52/16' ); $b = array( '192.168.128.0', // kein Treffer '192.168.11.255', // Treffer '62.10.11.255', // kein Treffer '62.10.11.12', // Treffer '128.255.255.255', // Treffer '129.255.255.255', // kein Treffer '96.50.255.255', // Treffer '97.50.51.52' // kein Treffer ); function f(array $a) { $new = array(); foreach ($a as $item) { list($ipv4, $cidr) = explode('/', $item); $index = implode('.', array_slice(explode('.', $ipv4), 0, $cidr >> 3)); $new[$index] = true; } return $new; } function g(array $a2, array $b) { foreach ($b as $item) { $parts = explode('.', $item); $tmp = ''; for ($i = 0; $i <= 3; $i++) { $tmp .= (('' !== $tmp) ? '.' : '') . $parts[$i]; if (isset($a2[$tmp])) { echo $item . '- Treffer' . "\n"; continue 2; } } echo $item . ' - kein Treffer' . "\n"; } } $a2 = f($a); g($a2, $b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2uSap
function name:  (null)
number of ops:  11
compiled vars:  !0 = $a, !1 = $b, !2 = $a2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   10     1        ASSIGN                                                       !1, <array>
   53     2        INIT_FCALL                                                   'f'
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $5      
          5        ASSIGN                                                       !2, $5
   54     6        INIT_FCALL                                                   'g'
          7        SEND_VAR                                                     !2
          8        SEND_VAR                                                     !1
          9        DO_FCALL                                          0          
         10      > RETURN                                                       1

Function f:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/2uSap
function name:  f
number of ops:  31
compiled vars:  !0 = $a, !1 = $new, !2 = $item, !3 = $ipv4, !4 = $cidr, !5 = $index
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   RECV                                                 !0      
   23     1        ASSIGN                                                       !1, <array>
   25     2      > FE_RESET_R                                           $7      !0, ->28
          3    > > FE_FETCH_R                                                   $7, !2, ->28
   26     4    >   INIT_FCALL                                                   'explode'
          5        SEND_VAL                                                     '%2F'
          6        SEND_VAR                                                     !2
          7        DO_ICALL                                             $8      
          8        FETCH_LIST_R                                         $9      $8, 0
          9        ASSIGN                                                       !3, $9
         10        FETCH_LIST_R                                         $11     $8, 1
         11        ASSIGN                                                       !4, $11
         12        FREE                                                         $8
   27    13        INIT_FCALL                                                   'array_slice'
         14        INIT_FCALL                                                   'explode'
         15        SEND_VAL                                                     '.'
         16        SEND_VAR                                                     !3
         17        DO_ICALL                                             $13     
         18        SEND_VAR                                                     $13
         19        SEND_VAL                                                     0
         20        SR                                                   ~14     !4, 3
         21        SEND_VAL                                                     ~14
         22        DO_ICALL                                             $15     
         23        FRAMELESS_ICALL_2                implode             ~16     '.', $15
         24        ASSIGN                                                       !5, ~16
   28    25        ASSIGN_DIM                                                   !1, !5
         26        OP_DATA                                                      <true>
   25    27      > JMP                                                          ->3
         28    >   FE_FREE                                                      $7
   31    29      > RETURN                                                       !1
   32    30*     > RETURN                                                       null

End of function f

Function g:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 33
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 33
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 12
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 12
Branch analysis from position: 29
Branch analysis from position: 12
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
Branch analysis from position: 26
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/2uSap
function name:  g
number of ops:  35
compiled vars:  !0 = $a2, !1 = $b, !2 = $item, !3 = $parts, !4 = $tmp, !5 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   36     2      > FE_RESET_R                                           $6      !1, ->33
          3    > > FE_FETCH_R                                                   $6, !2, ->33
   37     4    >   INIT_FCALL                                                   'explode'
          5        SEND_VAL                                                     '.'
          6        SEND_VAR                                                     !2
          7        DO_ICALL                                             $7      
          8        ASSIGN                                                       !3, $7
   38     9        ASSIGN                                                       !4, ''
   40    10        ASSIGN                                                       !5, 0
         11      > JMP                                                          ->27
   41    12    >   IS_NOT_IDENTICAL                                             !4, ''
         13      > JMPZ                                                         ~11, ->16
         14    >   QM_ASSIGN                                            ~12     '.'
         15      > JMP                                                          ->17
         16    >   QM_ASSIGN                                            ~12     ''
         17    >   FETCH_DIM_R                                          ~13     !3, !5
         18        CONCAT                                               ~14     ~12, ~13
         19        ASSIGN_OP                                         8          !4, ~14
   43    20        ISSET_ISEMPTY_DIM_OBJ                             0          !0, !4
         21      > JMPZ                                                         ~16, ->26
   44    22    >   CONCAT                                               ~17     !2, '-+Treffer'
         23        CONCAT                                               ~18     ~17, '%0A'
         24        ECHO                                                         ~18
   45    25      > JMP                                                          ->3
   40    26    >   PRE_INC                                                      !5
         27    >   IS_SMALLER_OR_EQUAL                                          !5, 3
         28      > JMPNZ                                                        ~20, ->12
   49    29    >   CONCAT                                               ~21     !2, '+-+kein+Treffer'
         30        CONCAT                                               ~22     ~21, '%0A'
         31        ECHO                                                         ~22
   36    32      > JMP                                                          ->3
         33    >   FE_FREE                                                      $6
   51    34      > RETURN                                                       null

End of function g

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.66 ms | 2183 KiB | 17 Q