3v4l.org

run code in 300+ 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 = 25
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/j0SbN
function name:  (null)
number of ops:  30
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, ->25
          7    > > FE_FETCH_R                                       ~12     $11, !3, ->25
          8    >   ASSIGN                                                   !4, ~12
   35     9        INIT_FCALL                                               'in_array'
         10        SEND_VAR                                                 !4
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $14     
         13      > JMPZ                                                     $14, ->24
   36    14    >   FETCH_DIM_R                                      ~15     !0, !4
         15        ASSIGN                                                   !5, ~15
   37    16        INIT_FCALL                                               'array_filter'
         17        SEND_VAR                                                 !3
         18        DECLARE_LAMBDA_FUNCTION                          ~18     [0]
         19        BIND_LEXICAL                                             ~18, !5
         20        SEND_VAL                                                 ~18
         21        DO_ICALL                                         $19     
         22        ASSIGN_DIM                                               !6, !4
         23        OP_DATA                                                  $19
   34    24    > > JMP                                                      ->7
         25    >   FE_FREE                                                  $11
   41    26        INIT_FCALL                                               'var_export'
         27        SEND_VAR                                                 !6
         28        DO_ICALL                                                 
         29      > 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}
number of ops:  9
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        INIT_FCALL                                               'in_array'
          3        FETCH_DIM_R                                      ~2      !0, 'field_name'
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
          8*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.57 ms | 1018 KiB | 17 Q