3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function findNetworkWithIPAddress(array $payload, string $ipAddress): array { $network = array_values(array_filter($payload, function (array $networkInfo) use ($ipAddress) { $address = $networkInfo['address'] ?? ''; /** for PHP < 8.0 */ // return substr($address, 0, strlen($ipAddress)) === $ipAddress; /** for PHP >= 8.0 */ return str_starts_with($address, $ipAddress); })); return reset($network) ?: []; } $payload = [ [ ".id" => "*1", "address" => "10.9.4.109/24", "network" => "10.9.4.0", "interface" => "ether1", "actual-interface" => "ether1", "invalid" => false, "dynamic" => false, "disabled" => false, ], [ ".id" => "*2", "address" => "10.9.4.209/24", "network" => "10.9.4.0", "interface" => "ether2", "actual-interface" => "ether2", "invalid" => false, "dynamic" => false, "disabled" => false, ], ]; $network = findNetworkWithIPAddress($payload, '10.9.4.209'); $interfaceName = $network['interface'] ?? ''; var_dump($interfaceName);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EYugm
function name:  (null)
number of ops:  14
compiled vars:  !0 = $payload, !1 = $network, !2 = $interfaceName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   44     1        INIT_FCALL                                               'findnetworkwithipaddress'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '10.9.4.209'
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !1, $4
   45     6        FETCH_DIM_IS                                     ~6      !1, 'interface'
          7        COALESCE                                         ~7      ~6
          8        QM_ASSIGN                                        ~7      ''
          9        ASSIGN                                                   !2, ~7
   47    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function findnetworkwithipaddress:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EYugm
function name:  findNetworkWithIPAddress
number of ops:  21
compiled vars:  !0 = $payload, !1 = $ipAddress, !2 = $network
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        INIT_FCALL                                               'array_values'
          3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !0
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FEYugm%3A7%240'
          6        BIND_LEXICAL                                             ~3, !1
   15     7        SEND_VAL                                                 ~3
          8        DO_ICALL                                         $4      
          9        SEND_VAR                                                 $4
         10        DO_ICALL                                         $5      
    7    11        ASSIGN                                                   !2, $5
   17    12        INIT_FCALL                                               'reset'
         13        SEND_REF                                                 !2
         14        DO_ICALL                                         $7      
         15        JMP_SET                                          ~8      $7, ->17
         16        QM_ASSIGN                                        ~8      <array>
         17        VERIFY_RETURN_TYPE                                       ~8
         18      > RETURN                                                   ~8
   18    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function findnetworkwithipaddress

Function %00%7Bclosure%7D%2Fin%2FEYugm%3A7%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EYugm
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $networkInfo, !1 = $ipAddress, !2 = $address
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    8     2        FETCH_DIM_IS                                     ~3      !0, 'address'
          3        COALESCE                                         ~4      ~3
          4        QM_ASSIGN                                        ~4      ''
          5        ASSIGN                                                   !2, ~4
   14     6        INIT_FCALL                                               'str_starts_with'
          7        SEND_VAR                                                 !2
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $6      
         10      > RETURN                                                   $6
   15    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FEYugm%3A7%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.23 ms | 1407 KiB | 24 Q