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; $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 = 25
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/9PfNC
function name:  (null)
number of ops:  32
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, ->25
          7    > > FE_FETCH_R                                               $9, !3, ->25
    9     8    >   MUL                                              ~10     !3, 100
          9        DIV                                              ~11     ~10, !1
         10        ASSIGN                                                   !4, ~11
   11    11        INIT_FCALL                                               'round'
         12        SEND_VAR                                                 !4
         13        SEND_VAL                                                 2
         14        DO_ICALL                                         $13     
         15        ASSIGN                                                   !4, $13
   12    16        ECHO                                                     !4
   13    17        ECHO                                                     '%0A'
   14    18        INIT_FCALL                                               'round'
         19        ADD                                              ~15     !2, !4
         20        SEND_VAL                                                 ~15
         21        SEND_VAL                                                 2
         22        DO_ICALL                                         $16     
         23        ASSIGN                                                   !2, $16
    7    24      > JMP                                                      ->7
         25    >   FE_FREE                                                  $9
   16    26        INIT_FCALL                                               'round'
         27        SEND_VAR                                                 !2
         28        SEND_VAL                                                 1
         29        DO_ICALL                                         $18     
         30        ECHO                                                     $18
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.06 ms | 1396 KiB | 17 Q