3v4l.org

run code in 300+ 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', '192.168.1.188/27' ); $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 '192.168.1.189', // Treffer '192.168.1.89' // kein Treffer ); function f(array $a) { $new = array(); foreach ($a as $item) { list($ipv4, $cidr) = explode('/', $item); $iplong = ip2long($ipv4); $iplong >>= 32 - $cidr; if (!isset($new[$cidr])) { $new[$cidr] = array(); } $new[$cidr][$iplong] = true; } return $new; } function g(array $a2, array $b) { foreach ($b as $item) { $iplong = ip2long($item); for ($i = 1; $i <= 32; $i++) { if (isset($a2[$i][$iplong >> 32 - $i])) { echo $item . '- Treffer' . '(' . $i . ')' . "\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/Fh0Fs
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>
   12     1        ASSIGN                                                   !1, <array>
   64     2        INIT_FCALL                                               'f'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !2, $5
   66     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
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/Fh0Fs
function name:  f
number of ops:  31
compiled vars:  !0 = $a, !1 = $new, !2 = $item, !3 = $ipv4, !4 = $cidr, !5 = $iplong
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        ASSIGN                                                   !1, <array>
   30     2      > FE_RESET_R                                       $7      !0, ->28
          3    > > FE_FETCH_R                                               $7, !2, ->28
   31     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
   33    13        INIT_FCALL                                               'ip2long'
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                         $13     
         16        ASSIGN                                                   !5, $13
   35    17        SUB                                              ~15     32, !4
         18        ASSIGN_OP                                     7          !5, ~15
   37    19        ISSET_ISEMPTY_DIM_OBJ                         0  ~17     !1, !4
         20        BOOL_NOT                                         ~18     ~17
         21      > JMPZ                                                     ~18, ->24
   38    22    >   ASSIGN_DIM                                               !1, !4
         23        OP_DATA                                                  <array>
   41    24    >   FETCH_DIM_W                                      $20     !1, !4
         25        ASSIGN_DIM                                               $20, !5
         26        OP_DATA                                                  <true>
   30    27      > JMP                                                      ->3
         28    >   FE_FREE                                                  $7
   44    29      > RETURN                                                   !1
   45    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 = 29
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 29
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 10
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 10
Branch analysis from position: 25
Branch analysis from position: 10
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/Fh0Fs
function name:  g
number of ops:  31
compiled vars:  !0 = $a2, !1 = $b, !2 = $item, !3 = $iplong, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   49     2      > FE_RESET_R                                       $5      !1, ->29
          3    > > FE_FETCH_R                                               $5, !2, ->29
   51     4    >   INIT_FCALL                                               'ip2long'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !3, $6
   53     8        ASSIGN                                                   !4, 1
          9      > JMP                                                      ->23
   54    10    >   SUB                                              ~10     32, !4
         11        SR                                               ~11     !3, ~10
         12        FETCH_DIM_IS                                     ~9      !0, !4
         13        ISSET_ISEMPTY_DIM_OBJ                         0          ~9, ~11
         14      > JMPZ                                                     ~12, ->22
   55    15    >   CONCAT                                           ~13     !2, '-+Treffer'
         16        CONCAT                                           ~14     ~13, '%28'
         17        CONCAT                                           ~15     ~14, !4
         18        CONCAT                                           ~16     ~15, '%29'
         19        CONCAT                                           ~17     ~16, '%0A'
         20        ECHO                                                     ~17
   56    21      > JMP                                                      ->3
   53    22    >   PRE_INC                                                  !4
         23    >   IS_SMALLER_OR_EQUAL                                      !4, 32
         24      > JMPNZ                                                    ~19, ->10
   60    25    >   CONCAT                                           ~20     !2, '+-+kein+Treffer'
         26        CONCAT                                           ~21     ~20, '%0A'
         27        ECHO                                                     ~21
   49    28      > JMP                                                      ->3
         29    >   FE_FREE                                                  $5
   62    30      > RETURN                                                   null

End of function g

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.96 ms | 1411 KiB | 19 Q