3v4l.org

run code in 300+ PHP versions simultaneously
<?php $vars = ['len' => '-1', 'start' => '0', 'cNum' => '7', 'cSearch_0' => 'b', 'cSearch_1' => 'c', 'cSearch_2' => 'd', 'cSearch_3' => 'e', 'cSearch_4' => 'f', 'cSearch_5' => 'g', 'cSearch_6' => 'h', 'cSort_0' => 'asc', 'cSort_1' => 'asc', 'search' => 'a']; function _filterArrayByKey(string $filter, $array){ return array_filter( $array, function($k) use ($filter){ return preg_match('/(' . $filter . ')/',$k); }, ARRAY_FILTER_USE_KEY ); } // $v = preg_grep('/[cSearch]\_/', array_keys($vars)); // $cSearch = array_filter($vars, function($k){ return preg_match('/(cSearch)/',$k);}, ARRAY_FILTER_USE_KEY); $cSort = _filterArrayByKey('cSort',$vars); var_dump($cSort); $o = ''; if(!empty($cSort)){ $cSortStr = '['; $cSortArr = []; foreach($cSort as $k => $v) { $cSortArr[] = '[' . (int) substr($k,-1) . ", '$v']"; } $o = $cSortStr .= implode(',',$cSortArr) . ']'; } var_dump($o);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 39
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 31
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 39
filename:       /in/1Sedu
function name:  (null)
number of ops:  43
compiled vars:  !0 = $vars, !1 = $cSort, !2 = $o, !3 = $cSortStr, !4 = $cSortArr, !5 = $v, !6 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   30     1        INIT_FCALL                                               '_filterarraybykey'
          2        SEND_VAL                                                 'cSort'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $8      
          5        ASSIGN                                                   !1, $8
   31     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   32     9        ASSIGN                                                   !2, ''
   33    10        ISSET_ISEMPTY_CV                                 ~12     !1
         11        BOOL_NOT                                         ~13     ~12
         12      > JMPZ                                                     ~13, ->39
   34    13    >   ASSIGN                                                   !3, '%5B'
   35    14        ASSIGN                                                   !4, <array>
   36    15      > FE_RESET_R                                       $16     !1, ->31
         16    > > FE_FETCH_R                                       ~17     $16, !5, ->31
         17    >   ASSIGN                                                   !6, ~17
   37    18        INIT_FCALL                                               'substr'
         19        SEND_VAR                                                 !6
         20        SEND_VAL                                                 -1
         21        DO_ICALL                                         $20     
         22        CAST                                          4  ~21     $20
         23        CONCAT                                           ~22     '%5B', ~21
         24        ROPE_INIT                                     3  ~24     '%2C+%27'
         25        ROPE_ADD                                      1  ~24     ~24, !5
         26        ROPE_END                                      2  ~23     ~24, '%27%5D'
         27        CONCAT                                           ~26     ~22, ~23
         28        ASSIGN_DIM                                               !4
         29        OP_DATA                                                  ~26
   36    30      > JMP                                                      ->16
         31    >   FE_FREE                                                  $16
   39    32        INIT_FCALL                                               'implode'
         33        SEND_VAL                                                 '%2C'
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                         $27     
         36        CONCAT                                           ~28     $27, '%5D'
         37        ASSIGN_OP                                     8  ~29     !3, ~28
         38        ASSIGN                                                   !2, ~29
   42    39    >   INIT_FCALL                                               'var_dump'
         40        SEND_VAR                                                 !2
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Function _filterarraybykey:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1Sedu
function name:  _filterArrayByKey
number of ops:  11
compiled vars:  !0 = $filter, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        INIT_FCALL                                               'array_filter'
   19     3        SEND_VAR                                                 !1
   20     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1Sedu%3A20%240'
          5        BIND_LEXICAL                                             ~2, !0
   22     6        SEND_VAL                                                 ~2
   23     7        SEND_VAL                                                 2
          8        DO_ICALL                                         $3      
          9      > RETURN                                                   $3
   25    10*     > RETURN                                                   null

End of function _filterarraybykey

Function %00%7Bclosure%7D%2Fin%2F1Sedu%3A20%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1Sedu
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $k, !1 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   21     2        INIT_FCALL                                               'preg_match'
          3        CONCAT                                           ~2      '%2F%28', !1
          4        CONCAT                                           ~3      ~2, '%29%2F'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8      > RETURN                                                   $4
   22     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1Sedu%3A20%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.58 ms | 1403 KiB | 24 Q