3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array(6,8,9,8,9,8,5,4,4,9); function Counting($array){ $freq_data = array_count_values($array); $unique_elements = array_map('intval',array_keys($freq_data)); $min_element = min($unique_elements); $max_element = max($unique_elements); $percentage_data = []; $total = count($array); for($i = $min_element; $i <= $max_element ; ++$i){ $current_percentage = isset($freq_data[$i]) ? ($freq_data[$i] / $total) : 0; $percentage_data[$i] = $i > $min_element ? $percentage_data[$i-1] + $current_percentage : $current_percentage; } uksort($percentage_data,function($a,$b){ return strnatcmp($a,$b); });// just to be sure that associative hash keys are in ascending order return $percentage_data; } print_r(Counting($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/41g2n
function name:  (null)
number of ops:  8
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   25     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'counting'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function counting:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 26
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 26
Branch analysis from position: 47
Branch analysis from position: 26
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 26
Branch analysis from position: 47
Branch analysis from position: 26
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
Branch analysis from position: 41
filename:       /in/41g2n
function name:  Counting
number of ops:  54
compiled vars:  !0 = $array, !1 = $freq_data, !2 = $unique_elements, !3 = $min_element, !4 = $max_element, !5 = $percentage_data, !6 = $total, !7 = $i, !8 = $current_percentage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'array_count_values'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $9      
          4        ASSIGN                                                   !1, $9
    5     5        INIT_FCALL                                               'array_map'
          6        SEND_VAL                                                 'intval'
          7        INIT_FCALL                                               'array_keys'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $11     
         10        SEND_VAR                                                 $11
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !2, $12
    7    13        INIT_FCALL                                               'min'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $14     
         16        ASSIGN                                                   !3, $14
    8    17        INIT_FCALL                                               'max'
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                         $16     
         20        ASSIGN                                                   !4, $16
   10    21        ASSIGN                                                   !5, <array>
   11    22        COUNT                                            ~19     !0
         23        ASSIGN                                                   !6, ~19
   13    24        ASSIGN                                                   !7, !3
         25      > JMP                                                      ->45
   14    26    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, !7
         27      > JMPZ                                                     ~22, ->32
         28    >   FETCH_DIM_R                                      ~23     !1, !7
         29        DIV                                              ~24     ~23, !6
         30        QM_ASSIGN                                        ~25     ~24
         31      > JMP                                                      ->33
         32    >   QM_ASSIGN                                        ~25     0
         33    >   ASSIGN                                                   !8, ~25
   15    34        IS_SMALLER                                               !3, !7
         35      > JMPZ                                                     ~28, ->41
         36    >   SUB                                              ~29     !7, 1
         37        FETCH_DIM_R                                      ~30     !5, ~29
         38        ADD                                              ~31     ~30, !8
         39        QM_ASSIGN                                        ~32     ~31
         40      > JMP                                                      ->42
         41    >   QM_ASSIGN                                        ~32     !8
         42    >   ASSIGN_DIM                                               !5, !7
         43        OP_DATA                                                  ~32
   13    44        PRE_INC                                                  !7
         45    >   IS_SMALLER_OR_EQUAL                                      !7, !4
         46      > JMPNZ                                                    ~34, ->26
   18    47    >   INIT_FCALL                                               'uksort'
         48        SEND_REF                                                 !5
         49        DECLARE_LAMBDA_FUNCTION                          ~35     [0]
   20    50        SEND_VAL                                                 ~35
   18    51        DO_ICALL                                                 
   22    52      > RETURN                                                   !5
   23    53*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/41g2n
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        INIT_FCALL                                               'strnatcmp'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
   20     7*     > RETURN                                                   null

End of Dynamic Function 0

End of function counting

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
134.48 ms | 1015 KiB | 22 Q