3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dbData = [ ["rate"=>'["1.55","1","1","1"]'], ["rate"=>'["2.55","2.55","2.55","2.55"]'], ["rate"=>'["1","1","1","1"]'], ["rate"=>'["1.55","2.55","3.55","4.56"]'] ]; $rate = array_map(function($a){ return json_decode($a['rate']); },$dbData); var_dump($rate); /* Replace by code above $rate = [ ["1.55","1","1","1"], ["2.55","2.55","2.55","2.55"], ["1","1","1","1"], ["1.2","1.21","1.2","1.2"] ]; */ $results =[]; // Count the columns in the first row for ($i = 0; $i<sizeof ($rate[0]); $i++) { // Extract each column in turn $col = array_column($rate, $i); // Calculate and store the averages $results[]= array_sum($col)/count($col); } var_dump($results);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 13
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 13
Branch analysis from position: 30
Branch analysis from position: 13
filename:       /in/X7haS
function name:  (null)
number of ops:  34
compiled vars:  !0 = $dbData, !1 = $rate, !2 = $results, !3 = $i, !4 = $col
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   11     1        INIT_FCALL                                               'array_map'
          2        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
   13     3        SEND_VAL                                                 ~6
          4        SEND_VAR                                                 !0
   11     5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !1, $7
   15     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   26    10        ASSIGN                                                   !2, <array>
   29    11        ASSIGN                                                   !3, 0
         12      > JMP                                                      ->26
   32    13    >   INIT_FCALL                                               'array_column'
         14        SEND_VAR                                                 !1
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $12     
         17        ASSIGN                                                   !4, $12
   36    18        INIT_FCALL                                               'array_sum'
         19        SEND_VAR                                                 !4
         20        DO_ICALL                                         $15     
         21        COUNT                                            ~16     !4
         22        DIV                                              ~17     $15, ~16
         23        ASSIGN_DIM                                               !2
         24        OP_DATA                                                  ~17
   29    25        PRE_INC                                                  !3
         26    >   FETCH_DIM_R                                      ~19     !1, 0
         27        COUNT                                            ~20     ~19
         28        IS_SMALLER                                               !3, ~20
         29      > JMPNZ                                                    ~21, ->13
   39    30    >   INIT_FCALL                                               'var_dump'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                                 
         33      > 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/X7haS
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'json_decode'
          2        FETCH_DIM_R                                      ~1      !0, 'rate'
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5      > RETURN                                                   $2
   13     6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.76 ms | 1011 KiB | 18 Q