3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(74.6779,25.918,44.9589); $total = array_sum($arr); $total_percentage = 0; foreach($arr as $total_item) { $percentage = ($total_item*100)/$total; var_dump($percentage); $percentage = round($percentage,2); // without this works, but result large numbers.. e.g: "51.305693800548" echo $percentage; echo "\n"; $total_percentage = round($total_percentage+$percentage,2); } echo round($total_percentage,1);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 28
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 28
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/pDU4v
function name:  (null)
number of ops:  35
compiled vars:  !0 = $arr, !1 = $total, !2 = $total_percentage, !3 = $total_item, !4 = $percentage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'array_sum'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
    6     5        ASSIGN                                                   !2, 0
    7     6      > FE_RESET_R                                       $9      !0, ->28
          7    > > FE_FETCH_R                                               $9, !3, ->28
    9     8    >   MUL                                              ~10     !3, 100
          9        DIV                                              ~11     ~10, !1
         10        ASSIGN                                                   !4, ~11
   10    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                                 
   12    14        INIT_FCALL                                               'round'
         15        SEND_VAR                                                 !4
         16        SEND_VAL                                                 2
         17        DO_ICALL                                         $14     
         18        ASSIGN                                                   !4, $14
   13    19        ECHO                                                     !4
   14    20        ECHO                                                     '%0A'
   15    21        INIT_FCALL                                               'round'
         22        ADD                                              ~16     !2, !4
         23        SEND_VAL                                                 ~16
         24        SEND_VAL                                                 2
         25        DO_ICALL                                         $17     
         26        ASSIGN                                                   !2, $17
    7    27      > JMP                                                      ->7
         28    >   FE_FREE                                                  $9
   17    29        INIT_FCALL                                               'round'
         30        SEND_VAR                                                 !2
         31        SEND_VAL                                                 1
         32        DO_ICALL                                         $19     
         33        ECHO                                                     $19
         34      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.95 ms | 1396 KiB | 19 Q