3v4l.org

run code in 300+ PHP versions simultaneously
<?php $closeStockPrice = [ 'A' => 50, 'B' => 155, 'C' => 75, 'D' => 245, 'E' => 300, 'F' => 100, 'G' => 153, ]; $average = array_sum($closeStockPrice) / count($closeStockPrice); $bestDistances = []; foreach ($closeStockPrice as $business => $price) { $distance = abs($average - $price); $current = current($bestDistances); if (!$bestDistances || $current > $distance) { $bestDistances = [$business => $distance]; } elseif ($current === $distance) { $bestDistances[$business] = $distance; } } var_export([ 'average' => $average, 'bestDistances' => $bestDistances, 'bestBusinessPrices' => array_intersect_key($closeStockPrice, $bestDistances) ]);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 33
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 33
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 32
Branch analysis from position: 24
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/ULrM6
function name:  (null)
number of ops:  45
compiled vars:  !0 = $closeStockPrice, !1 = $average, !2 = $bestDistances, !3 = $price, !4 = $business, !5 = $distance, !6 = $current
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'array_sum'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        COUNT                                            ~9      !0
          5        DIV                                              ~10     $8, ~9
          6        ASSIGN                                                   !1, ~10
   15     7        ASSIGN                                                   !2, <array>
   16     8      > FE_RESET_R                                       $13     !0, ->33
          9    > > FE_FETCH_R                                       ~14     $13, !3, ->33
         10    >   ASSIGN                                                   !4, ~14
   17    11        INIT_FCALL                                               'abs'
         12        SUB                                              ~16     !1, !3
         13        SEND_VAL                                                 ~16
         14        DO_ICALL                                         $17     
         15        ASSIGN                                                   !5, $17
   18    16        INIT_FCALL                                               'current'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $19     
         19        ASSIGN                                                   !6, $19
   19    20        BOOL_NOT                                         ~21     !2
         21      > JMPNZ_EX                                         ~21     ~21, ->24
         22    >   IS_SMALLER                                       ~22     !5, !6
         23        BOOL                                             ~21     ~22
         24    > > JMPZ                                                     ~21, ->28
   20    25    >   INIT_ARRAY                                       ~23     !5, !4
         26        ASSIGN                                                   !2, ~23
   19    27      > JMP                                                      ->32
   21    28    >   IS_IDENTICAL                                             !6, !5
         29      > JMPZ                                                     ~25, ->32
   22    30    >   ASSIGN_DIM                                               !2, !4
         31        OP_DATA                                                  !5
   16    32    > > JMP                                                      ->9
         33    >   FE_FREE                                                  $13
   25    34        INIT_FCALL                                               'var_export'
   26    35        INIT_ARRAY                                       ~27     !1, 'average'
   27    36        ADD_ARRAY_ELEMENT                                ~27     !2, 'bestDistances'
   28    37        INIT_FCALL                                               'array_intersect_key'
         38        SEND_VAR                                                 !0
         39        SEND_VAR                                                 !2
         40        DO_ICALL                                         $28     
         41        ADD_ARRAY_ELEMENT                                ~27     $28, 'bestBusinessPrices'
         42        SEND_VAL                                                 ~27
   25    43        DO_ICALL                                                 
   29    44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.19 ms | 1009 KiB | 18 Q