3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* function balancedTagCloud(array $values, array $priorities): array { $low = min($priorities) - 1; $high = max($priorities) - $low; return array_map( fn($v, $p) => sprintf( '<h%1$d>%2$s</h%1$d>', ceil(($p - $low) / $high * 6), $v ), $values, $priorities ); } */ $artist = ["the roots", "michael jackson", "billy idol", "more", "and more", "and_YET_MORE"]; /*$counts = [ 'original' => [5, 3, 9, 1, 1, 3], 'no_ones' => [5, 3, 9, 7, 7, 3], 'skewed' => [5, 3, 9, 7, 111, 3], 'all_same' => [5, 5, 5, 5, 5, 5], 'only_two' => [9, 20, 9, 20, 9, 20], ]; foreach ($counts as $count) { echo implode("\n", balancedTagCloud($artist, $count)); echo "\n---\n"; }*/ $count = [5, 3, 9, 1, 1, 3]; $steps = 6; $tags = []; $min = 1e9; $max = -1e9; foreach ($artist as $i => $name) { $c = log($count[$i]); $min = min($min, $c); $max = max($max, $c); $tags[] = (object) ['weight' => $count[$i], 'name' => $name, 'count' => $c]; } $range = max(.01, $max - $min) * 1.0001; foreach ($tags as $obj) { $obj->weight = 1 + floor($steps * ($obj->count - $min) / $range); } foreach ($tags as $tag) { echo "<h$tag->weight>$tag->name</h$tag->weight>\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 32
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 32
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 53
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 53
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 53
2 jumps found. (Code = 77) Position 1 = 55, Position 2 = 68
Branch analysis from position: 55
2 jumps found. (Code = 78) Position 1 = 56, Position 2 = 68
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 53
Branch analysis from position: 32
filename:       /in/dv3gv
function name:  (null)
number of ops:  70
compiled vars:  !0 = $artist, !1 = $count, !2 = $steps, !3 = $tags, !4 = $min, !5 = $max, !6 = $name, !7 = $i, !8 = $c, !9 = $range, !10 = $obj, !11 = $tag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   32     1        ASSIGN                                                   !1, <array>
   34     2        ASSIGN                                                   !2, 6
   35     3        ASSIGN                                                   !3, <array>
   36     4        ASSIGN                                                   !4, 1.0e+9
   37     5        ASSIGN                                                   !5, -1.0e+9
   39     6      > FE_RESET_R                                       $18     !0, ->32
          7    > > FE_FETCH_R                                       ~19     $18, !6, ->32
          8    >   ASSIGN                                                   !7, ~19
   40     9        INIT_FCALL                                               'log'
         10        FETCH_DIM_R                                      ~21     !1, !7
         11        SEND_VAL                                                 ~21
         12        DO_ICALL                                         $22     
         13        ASSIGN                                                   !8, $22
   41    14        INIT_FCALL                                               'min'
         15        SEND_VAR                                                 !4
         16        SEND_VAR                                                 !8
         17        DO_ICALL                                         $24     
         18        ASSIGN                                                   !4, $24
   42    19        INIT_FCALL                                               'max'
         20        SEND_VAR                                                 !5
         21        SEND_VAR                                                 !8
         22        DO_ICALL                                         $26     
         23        ASSIGN                                                   !5, $26
   43    24        FETCH_DIM_R                                      ~29     !1, !7
         25        INIT_ARRAY                                       ~30     ~29, 'weight'
         26        ADD_ARRAY_ELEMENT                                ~30     !6, 'name'
         27        ADD_ARRAY_ELEMENT                                ~30     !8, 'count'
         28        CAST                                          8  ~31     ~30
         29        ASSIGN_DIM                                               !3
         30        OP_DATA                                                  ~31
   39    31      > JMP                                                      ->7
         32    >   FE_FREE                                                  $18
   45    33        INIT_FCALL                                               'max'
         34        SEND_VAL                                                 0.01
         35        SUB                                              ~32     !5, !4
         36        SEND_VAL                                                 ~32
         37        DO_ICALL                                         $33     
         38        MUL                                              ~34     $33, 1.0001
         39        ASSIGN                                                   !9, ~34
   47    40      > FE_RESET_R                                       $36     !3, ->53
         41    > > FE_FETCH_R                                               $36, !10, ->53
   48    42    >   INIT_FCALL                                               'floor'
         43        FETCH_OBJ_R                                      ~38     !10, 'count'
         44        SUB                                              ~39     ~38, !4
         45        MUL                                              ~40     !2, ~39
         46        DIV                                              ~41     ~40, !9
         47        SEND_VAL                                                 ~41
         48        DO_ICALL                                         $42     
         49        ADD                                              ~43     1, $42
         50        ASSIGN_OBJ                                               !10, 'weight'
         51        OP_DATA                                                  ~43
   47    52      > JMP                                                      ->41
         53    >   FE_FREE                                                  $36
   51    54      > FE_RESET_R                                       $44     !3, ->68
         55    > > FE_FETCH_R                                               $44, !11, ->68
   52    56    >   ROPE_INIT                                     7  ~49     '%3Ch'
         57        FETCH_OBJ_R                                      ~45     !11, 'weight'
         58        ROPE_ADD                                      1  ~49     ~49, ~45
         59        ROPE_ADD                                      2  ~49     ~49, '%3E'
         60        FETCH_OBJ_R                                      ~46     !11, 'name'
         61        ROPE_ADD                                      3  ~49     ~49, ~46
         62        ROPE_ADD                                      4  ~49     ~49, '%3C%2Fh'
         63        FETCH_OBJ_R                                      ~47     !11, 'weight'
         64        ROPE_ADD                                      5  ~49     ~49, ~47
         65        ROPE_END                                      6  ~48     ~49, '%3E%0A'
         66        ECHO                                                     ~48
   51    67      > JMP                                                      ->55
         68    >   FE_FREE                                                  $44
   53    69      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.99 ms | 1018 KiB | 17 Q