3v4l.org

run code in 500+ PHP versions simultaneously
<?php $conditionalFieldsWhitelist = [ 'Basic Fields' => [ 'contact_name', 'contact_lastname', ] ]; $myArray = [ 'Basic Fields' => [ [ 'field_name' => 'contact_name', 'field_type' => 'string', 'field_required' => 'no', ], [ 'field_name' => 'contact_lastname', 'field_type' => 'string', 'field_required' => 'no', ], [ 'field_name' => 'contact_email', 'field_type' => 'string', 'field_required' => 'yes', 'field_placeholder' => 'example@domain.com' ], [ 'field_name' => 'contact_mobile', 'field_type' => 'string', 'field_required' => 'yes', 'field_placeholder' => '+27881234567' ] ] ]; $whitegroups = array_keys($conditionalFieldsWhitelist); // only necessary if multiple groups foreach ($myArray as $group => $field_sets) { if (in_array($group, $whitegroups)) { $whitesubsets = $conditionalFieldsWhitelist[$group]; $result[$group] = array_filter($field_sets, function($set) use ($whitesubsets) { return in_array($set['field_name'],$whitesubsets);}); } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 21
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/j0SbN
function name:  (null)
number of ops:  27
compiled vars:  !0 = $conditionalFieldsWhitelist, !1 = $myArray, !2 = $whitegroups, !3 = $field_sets, !4 = $group, !5 = $whitesubsets, !6 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
    9     1        ASSIGN                                                       !1, <array>
   32     2        INIT_FCALL                                                   'array_keys'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $9      
          5        ASSIGN                                                       !2, $9
   34     6      > FE_RESET_R                                           $11     !1, ->22
          7    > > FE_FETCH_R                                           ~12     $11, !3, ->22
          8    >   ASSIGN                                                       !4, ~12
   35     9        FRAMELESS_ICALL_2                in_array            ~14     !4, !2
         10      > JMPZ                                                         ~14, ->21
   36    11    >   FETCH_DIM_R                                          ~15     !0, !4
         12        ASSIGN                                                       !5, ~15
   37    13        INIT_FCALL                                                   'array_filter'
         14        SEND_VAR                                                     !3
         15        DECLARE_LAMBDA_FUNCTION                              ~18     [0]
         16        BIND_LEXICAL                                                 ~18, !5
         17        SEND_VAL                                                     ~18
         18        DO_ICALL                                             $19     
         19        ASSIGN_DIM                                                   !6, !4
         20        OP_DATA                                                      $19
   34    21    > > JMP                                                          ->7
         22    >   FE_FREE                                                      $11
   41    23        INIT_FCALL                                                   'var_export'
         24        SEND_VAR                                                     !6
         25        DO_ICALL                                                     
         26      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j0SbN
function name:  {closure:/in/j0SbN:37}
number of ops:  6
compiled vars:  !0 = $set, !1 = $whitesubsets
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        FETCH_DIM_R                                          ~2      !0, 'field_name'
          3        FRAMELESS_ICALL_2                in_array            ~3      ~2, !1
          4      > RETURN                                                       ~3
          5*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
185.25 ms | 2648 KiB | 16 Q