3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Capture the list of taste observations across analyses and phases of analysis $taste_observations = array(); // Temporary test data for Stack Overflow Question $taste_observations[] = [ 'analyst' => 'Ken', 'phase' => 'Entrance', 'taste' => 'Sweet', 'intensity' => 1 ]; $taste_observations[] = [ 'analyst' => 'Ken', 'phase' => 'Entrance', 'taste' => 'Spicy', 'intensity' => 1 ]; $taste_observations[] = [ 'analyst' => 'Ken', 'phase' => 'Center', 'taste' => 'Sweet', 'intensity' => 2 ]; $taste_observations[] = [ 'analyst' => 'Bob', 'phase' => 'Entrance', 'taste' => 'Savory', 'intensity' => 1 ]; $taste_observations[] = [ 'analyst' => 'Bob', 'phase' => 'After', 'taste' => 'Sweet', 'intensity' => 2, ]; $taste_summary = []; foreach($taste_observations as $taste_observation) { $taste_summary[$taste_observation['taste']] = [ 'taste' => $taste_observation['taste'], 'count' => 1 + ($taste_summary[$taste_observation['taste']]['count'] ?? 0), 'max' => max($taste_summary[$taste_observation['taste']]['max'] ?? 0, $taste_observation['intensity']), 'sum' => $taste_observation['intensity'] + ($taste_summary[$taste_observation['taste']]['sum'] ?? 0) ]; } ksort($taste_summary); $taste_summary = array_values($taste_summary); print_r($taste_summary);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 46
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 46
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
filename:       /in/GTZPD
function name:  (null)
number of ops:  58
compiled vars:  !0 = $taste_observations, !1 = $taste_summary, !2 = $taste_observation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    6     1        ASSIGN_DIM                                               !0
    7     2        OP_DATA                                                  <array>
   12     3        ASSIGN_DIM                                               !0
   13     4        OP_DATA                                                  <array>
   18     5        ASSIGN_DIM                                               !0
   19     6        OP_DATA                                                  <array>
   24     7        ASSIGN_DIM                                               !0
   25     8        OP_DATA                                                  <array>
   30     9        ASSIGN_DIM                                               !0
   31    10        OP_DATA                                                  <array>
   37    11        ASSIGN                                                   !1, <array>
   38    12      > FE_RESET_R                                       $10     !0, ->46
         13    > > FE_FETCH_R                                               $10, !2, ->46
   39    14    >   FETCH_DIM_R                                      ~11     !2, 'taste'
   40    15        FETCH_DIM_R                                      ~13     !2, 'taste'
         16        INIT_ARRAY                                       ~14     ~13, 'taste'
   41    17        FETCH_DIM_R                                      ~15     !2, 'taste'
         18        FETCH_DIM_IS                                     ~16     !1, ~15
         19        FETCH_DIM_IS                                     ~17     ~16, 'count'
         20        COALESCE                                         ~18     ~17
         21        QM_ASSIGN                                        ~18     0
         22        ADD                                              ~19     1, ~18
         23        ADD_ARRAY_ELEMENT                                ~14     ~19, 'count'
   42    24        INIT_FCALL                                               'max'
         25        FETCH_DIM_R                                      ~20     !2, 'taste'
         26        FETCH_DIM_IS                                     ~21     !1, ~20
         27        FETCH_DIM_IS                                     ~22     ~21, 'max'
         28        COALESCE                                         ~23     ~22
         29        QM_ASSIGN                                        ~23     0
         30        SEND_VAL                                                 ~23
         31        FETCH_DIM_R                                      ~24     !2, 'intensity'
         32        SEND_VAL                                                 ~24
         33        DO_ICALL                                         $25     
         34        ADD_ARRAY_ELEMENT                                ~14     $25, 'max'
   43    35        FETCH_DIM_R                                      ~26     !2, 'intensity'
         36        FETCH_DIM_R                                      ~27     !2, 'taste'
         37        FETCH_DIM_IS                                     ~28     !1, ~27
         38        FETCH_DIM_IS                                     ~29     ~28, 'sum'
         39        COALESCE                                         ~30     ~29
         40        QM_ASSIGN                                        ~30     0
         41        ADD                                              ~31     ~26, ~30
         42        ADD_ARRAY_ELEMENT                                ~14     ~31, 'sum'
   39    43        ASSIGN_DIM                                               !1, ~11
   43    44        OP_DATA                                                  ~14
   38    45      > JMP                                                      ->13
         46    >   FE_FREE                                                  $10
   46    47        INIT_FCALL                                               'ksort'
         48        SEND_REF                                                 !1
         49        DO_ICALL                                                 
   47    50        INIT_FCALL                                               'array_values'
         51        SEND_VAR                                                 !1
         52        DO_ICALL                                         $33     
         53        ASSIGN                                                   !1, $33
   48    54        INIT_FCALL                                               'print_r'
         55        SEND_VAR                                                 !1
         56        DO_ICALL                                                 
         57      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.3 ms | 1006 KiB | 17 Q