3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 配列を取得してゴール $result = getArr( [ 'datatype'=>'array', 'use'=>['action'] ] ); var_dump( $result ); // $basesから$argsの指定に応じて配列を取得する function getArr( $args ){ $bases = [ [ 'key'=>'follwoers_arr', 'label'=>'フォロワー', 'datatype'=>'arr', 'use'=>['front','action'] ], // ここに追加したい [ 'key'=>'follwoees_arr', 'label'=>'フォロー中', 'datatype'=>'arr', 'use'=>['front','action'] ], // ここに追加したい [ 'key'=>'age', 'label'=>'年齢', 'datatype'=>'str', 'use'=>['profile'] ], ]; // 「カウント情報」を「ここに追加したい」の行に追加したい $row_arr = getArr( [ 'datatype'=>'arr', 'use'=>['action'] ] ); $count_row = []; foreach( $row_arr as $row ){ foreach( $row as $key=>$val ){ if( $key=='key' ){ $key_all = str_replace( '_arr', '_count_all', $val ); $key_week = str_replace( '_arr', '_count_week', $val ); $bases[] = [ 'key'=>$key_all, 'label'=>'全期間', 'datatype'=>'str', 'use'=>['auto'] ]; // カウント情報 $bases[] = [ 'key'=>$key_week, 'label'=>'一週間', 'datatype'=>'str', 'use'=>['auto'] ]; // カウント情報 } } } // 引数$argsと一致する行の配列を返す $result = []; foreach ($bases as $base){ if (isMatch($args, $base)) { $result[] = $base; } } return $result; } // 引数$argsと一致する行の配列を返す function isMatch($args, $set) { foreach ($args as $key => $vals) { if (!array_key_exists($key, $set)) { return false; } if (is_array($vals)) { foreach ($vals as $val) { if (!in_array($val, $set[$key], true)) { return false; } } } else { if ($vals !== $set[$key]) { return false; } } } return true; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GYLYN
function name:  (null)
number of ops:  8
compiled vars:  !0 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'getArr'
          1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
    4     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
   61     7      > RETURN                                                   1

Function getarr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 41
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 41
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 39
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 39
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 38
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 38
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 39
Branch analysis from position: 41
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 53
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 53
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 52
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 52
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 41
filename:       /in/GYLYN
function name:  getArr
number of ops:  56
compiled vars:  !0 = $args, !1 = $bases, !2 = $row_arr, !3 = $count_row, !4 = $row, !5 = $val, !6 = $key, !7 = $key_all, !8 = $key_week, !9 = $result, !10 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        ASSIGN                                                   !1, <array>
   18     2        INIT_FCALL_BY_NAME                                       'getArr'
          3        SEND_VAL_EX                                              <array>
          4        DO_FCALL                                      0  $12     
          5        ASSIGN                                                   !2, $12
   19     6        ASSIGN                                                   !3, <array>
   20     7      > FE_RESET_R                                       $15     !2, ->41
          8    > > FE_FETCH_R                                               $15, !4, ->41
   21     9    > > FE_RESET_R                                       $16     !4, ->39
         10    > > FE_FETCH_R                                       ~17     $16, !5, ->39
         11    >   ASSIGN                                                   !6, ~17
   22    12        IS_EQUAL                                                 !6, 'key'
         13      > JMPZ                                                     ~19, ->38
   23    14    >   INIT_FCALL                                               'str_replace'
         15        SEND_VAL                                                 '_arr'
         16        SEND_VAL                                                 '_count_all'
         17        SEND_VAR                                                 !5
         18        DO_ICALL                                         $20     
         19        ASSIGN                                                   !7, $20
   24    20        INIT_FCALL                                               'str_replace'
         21        SEND_VAL                                                 '_arr'
         22        SEND_VAL                                                 '_count_week'
         23        SEND_VAR                                                 !5
         24        DO_ICALL                                         $22     
         25        ASSIGN                                                   !8, $22
   25    26        INIT_ARRAY                                       ~25     !7, 'key'
         27        ADD_ARRAY_ELEMENT                                ~25     '%E5%85%A8%E6%9C%9F%E9%96%93', 'label'
         28        ADD_ARRAY_ELEMENT                                ~25     'str', 'datatype'
         29        ADD_ARRAY_ELEMENT                                ~25     <array>, 'use'
         30        ASSIGN_DIM                                               !1
         31        OP_DATA                                                  ~25
   26    32        INIT_ARRAY                                       ~27     !8, 'key'
         33        ADD_ARRAY_ELEMENT                                ~27     '%E4%B8%80%E9%80%B1%E9%96%93', 'label'
         34        ADD_ARRAY_ELEMENT                                ~27     'str', 'datatype'
         35        ADD_ARRAY_ELEMENT                                ~27     <array>, 'use'
         36        ASSIGN_DIM                                               !1
         37        OP_DATA                                                  ~27
   21    38    > > JMP                                                      ->10
         39    >   FE_FREE                                                  $16
   20    40      > JMP                                                      ->8
         41    >   FE_FREE                                                  $15
   32    42        ASSIGN                                                   !9, <array>
   33    43      > FE_RESET_R                                       $29     !1, ->53
         44    > > FE_FETCH_R                                               $29, !10, ->53
   34    45    >   INIT_FCALL_BY_NAME                                       'isMatch'
         46        SEND_VAR_EX                                              !0
         47        SEND_VAR_EX                                              !10
         48        DO_FCALL                                      0  $30     
         49      > JMPZ                                                     $30, ->52
   35    50    >   ASSIGN_DIM                                               !9
         51        OP_DATA                                                  !10
   33    52    > > JMP                                                      ->44
         53    >   FE_FREE                                                  $29
   38    54      > RETURN                                                   !9
   39    55*     > RETURN                                                   null

End of function getarr

Function ismatch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 34
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 34
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 28
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/GYLYN
function name:  isMatch
number of ops:  37
compiled vars:  !0 = $args, !1 = $set, !2 = $vals, !3 = $key, !4 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   43     2      > FE_RESET_R                                       $5      !0, ->34
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->34
          4    >   ASSIGN                                                   !3, ~6
   44     5        ARRAY_KEY_EXISTS                                 ~8      !3, !1
          6        BOOL_NOT                                         ~9      ~8
          7      > JMPZ                                                     ~9, ->10
   45     8    >   FE_FREE                                                  $5
          9      > RETURN                                                   <false>
   47    10    >   TYPE_CHECK                                  128          !2
         11      > JMPZ                                                     ~10, ->28
   48    12    > > FE_RESET_R                                       $11     !2, ->26
         13    > > FE_FETCH_R                                               $11, !4, ->26
   49    14    >   INIT_FCALL                                               'in_array'
         15        SEND_VAR                                                 !4
         16        FETCH_DIM_R                                      ~12     !1, !3
         17        SEND_VAL                                                 ~12
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $13     
         20        BOOL_NOT                                         ~14     $13
         21      > JMPZ                                                     ~14, ->25
   50    22    >   FE_FREE                                                  $11
         23        FE_FREE                                                  $5
         24      > RETURN                                                   <false>
   48    25    > > JMP                                                      ->13
         26    >   FE_FREE                                                  $11
   47    27      > JMP                                                      ->33
   55    28    >   FETCH_DIM_R                                      ~15     !1, !3
         29        IS_NOT_IDENTICAL                                         !2, ~15
         30      > JMPZ                                                     ~16, ->33
   56    31    >   FE_FREE                                                  $5
         32      > RETURN                                                   <false>
   43    33    > > JMP                                                      ->3
         34    >   FE_FREE                                                  $5
   60    35      > RETURN                                                   <true>
   61    36*     > RETURN                                                   null

End of function ismatch

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.75 ms | 1025 KiB | 16 Q