3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ar = array('mopo_1' => 'honta', 'hinta' => 200, 'mopo_2' => 'jamaha', 'hinta' => 320, 'mopo_3' => 'susuki', 'hinta' => 310); function array_key_exists_wildcard ( $array, $search, $return = '' ) { $search = str_replace( '\*', '.*?', preg_quote( $search, '/' ) ); $result = preg_grep( '/^' . $search . '$/i', array_keys( $array ) ); if ( $return == 'key-value' ) return array_intersect_key( $array, array_flip( $result ) ); return $result; } $search = 'mopo*'; print_r( array_key_exists_wildcard( $ar, $search ) ); print_r( array_key_exists_wildcard( $ar, $search, 'key-value' ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nYOeO
function name:  (null)
number of ops:  18
compiled vars:  !0 = $ar, !1 = $search
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, 'mopo%2A'
   15     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'array_key_exists_wildcard'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   16     9        INIT_FCALL                                               'print_r'
         10        INIT_FCALL                                               'array_key_exists_wildcard'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        SEND_VAL                                                 'key-value'
         14        DO_FCALL                                      0  $6      
         15        SEND_VAR                                                 $6
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function array_key_exists_wildcard:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nYOeO
function name:  array_key_exists_wildcard
number of ops:  35
compiled vars:  !0 = $array, !1 = $search, !2 = $return, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      ''
    7     3        INIT_FCALL                                               'str_replace'
          4        SEND_VAL                                                 '%5C%2A'
          5        SEND_VAL                                                 '.%2A%3F'
          6        INIT_FCALL                                               'preg_quote'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 '%2F'
          9        DO_ICALL                                         $4      
         10        SEND_VAR                                                 $4
         11        DO_ICALL                                         $5      
         12        ASSIGN                                                   !1, $5
    8    13        INIT_FCALL                                               'preg_grep'
         14        CONCAT                                           ~7      '%2F%5E', !1
         15        CONCAT                                           ~8      ~7, '%24%2Fi'
         16        SEND_VAL                                                 ~8
         17        INIT_FCALL                                               'array_keys'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $9      
         20        SEND_VAR                                                 $9
         21        DO_ICALL                                         $10     
         22        ASSIGN                                                   !3, $10
    9    23        IS_EQUAL                                                 !2, 'key-value'
         24      > JMPZ                                                     ~12, ->33
   10    25    >   INIT_FCALL                                               'array_intersect_key'
         26        SEND_VAR                                                 !0
         27        INIT_FCALL                                               'array_flip'
         28        SEND_VAR                                                 !3
         29        DO_ICALL                                         $13     
         30        SEND_VAR                                                 $13
         31        DO_ICALL                                         $14     
         32      > RETURN                                                   $14
   11    33    > > RETURN                                                   !3
   12    34*     > RETURN                                                   null

End of function array_key_exists_wildcard

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.8 ms | 1403 KiB | 29 Q