3v4l.org

run code in 300+ PHP versions simultaneously
<?php $multidimensionArray = [ "A2" => [ 0 => "A1", 1 => "A2", 2 => "A3", ], "A1" => [ 0 => "A1", 1 => "A6", 2 => "A5", 3 => "A2", ], "A6" => [ 0 => "A3", ], "A3" => [ 0 => "A3", 1 => "A2", ], "A5" => [ 0 => "A4" ], "A4" => [ 0 => "A4", 1 => "A3", ] ]; $singeArray = [ "A1" => 675.58333333333, "A2" => 1786.75, "A3" => 2897.9166666667, "A4" => 4009.0833333333, "A5" => 5120.25, "A6" => 6231.4166666667, ]; $results = []; foreach ($multidimensionArray as $key => $valueArr) { ## filter out all values of interest from $singleArray $filteredValues = array_filter($singeArray, function ($value, $identifier) use ($valueArr) { return in_array($identifier, $valueArr); }, ARRAY_FILTER_USE_BOTH); ## Here we get the average $results[$key] = array_sum($filteredValues) / count($filteredValues); } print_r($results);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/PFnKO
function name:  (null)
number of ops:  27
compiled vars:  !0 = $multidimensionArray, !1 = $singeArray, !2 = $results, !3 = $valueArr, !4 = $key, !5 = $filteredValues
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   30     1        ASSIGN                                                   !1, <array>
   38     2        ASSIGN                                                   !2, <array>
   39     3      > FE_RESET_R                                       $9      !0, ->22
          4    > > FE_FETCH_R                                       ~10     $9, !3, ->22
          5    >   ASSIGN                                                   !4, ~10
   41     6        INIT_FCALL                                               'array_filter'
          7        SEND_VAR                                                 !1
          8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FPFnKO%3A41%240'
          9        BIND_LEXICAL                                             ~12, !3
   43    10        SEND_VAL                                                 ~12
         11        SEND_VAL                                                 1
         12        DO_ICALL                                         $13     
   41    13        ASSIGN                                                   !5, $13
   45    14        INIT_FCALL                                               'array_sum'
         15        SEND_VAR                                                 !5
         16        DO_ICALL                                         $16     
         17        COUNT                                            ~17     !5
         18        DIV                                              ~18     $16, ~17
         19        ASSIGN_DIM                                               !2, !4
         20        OP_DATA                                                  ~18
   39    21      > JMP                                                      ->4
         22    >   FE_FREE                                                  $9
   47    23        INIT_FCALL                                               'print_r'
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FPFnKO%3A41%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PFnKO
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $value, !1 = $identifier, !2 = $valueArr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   42     3        INIT_FCALL                                               'in_array'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
   43     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FPFnKO%3A41%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.35 ms | 1411 KiB | 21 Q