3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [6,4,9,3,8,2,1,5]; // Calculate the total of the array elements $sum = array_sum($arr); $len = count($arr); // Using integer division and modulo arithmetic calculate the average and remainder $avg = intdiv($sum,$len); $rem = $sum % $len; // Create a result array and fill with the average $result = array_fill(0,$len,$avg); // Spread the remainder over the first few elements. while($rem){$result[--$rem]++;} var_dump($result); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 21
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 21
Branch analysis from position: 25
Branch analysis from position: 21
filename:       /in/nY2Fo
function name:  (null)
number of ops:  29
compiled vars:  !0 = $arr, !1 = $sum, !2 = $len, !3 = $avg, !4 = $rem, !5 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
    5     1        INIT_FCALL                                                   'array_sum'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $7      
          4        ASSIGN                                                       !1, $7
    6     5        COUNT                                                ~9      !0
          6        ASSIGN                                                       !2, ~9
    9     7        INIT_FCALL                                                   'intdiv'
          8        SEND_VAR                                                     !1
          9        SEND_VAR                                                     !2
         10        DO_ICALL                                             $11     
         11        ASSIGN                                                       !3, $11
   10    12        MOD                                                  ~13     !1, !2
         13        ASSIGN                                                       !4, ~13
   13    14        INIT_FCALL                                                   'array_fill'
         15        SEND_VAL                                                     0
         16        SEND_VAR                                                     !2
         17        SEND_VAR                                                     !3
         18        DO_ICALL                                             $15     
         19        ASSIGN                                                       !5, $15
   16    20      > JMP                                                          ->24
         21    >   PRE_DEC                                              ~17     !4
         22        FETCH_DIM_RW                                         $18     !5, ~17
         23        PRE_INC                                                      $18
         24    > > JMPNZ                                                        !4, ->21
   17    25    >   INIT_FCALL                                                   'var_dump'
         26        SEND_VAR                                                     !5
         27        DO_ICALL                                                     
   18    28      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.49 ms | 1907 KiB | 17 Q