3v4l.org

run code in 300+ PHP versions simultaneously
<?php function word_cloud($words, $div_size = 400) { $tags = 0; $cloud = "<div style=\"width: {$div_size}px\">"; /* This word cloud generation algorithm was taken from the Wikipedia page on "word cloud" with some minor modifications to the implementation */ /* Initialize some variables */ $fmax = 96; /* Maximum font size */ $fmin = 8; /* Minimum font size */ $tmin = min($words); /* Frequency lower-bound */ $tmax = max($words); /* Frequency upper-bound */ foreach ($words as $word => $frequency) { if ($frequency > $tmin) { $font_size = floor( ( $fmax * ($frequency - $tmin) ) / ( $tmax - $tmin ) ); /* Define a color index based on the frequency of the word */ $r = $g = 0; $b = floor( 255 * ($frequency / $tmax) ); $color = '#' . sprintf('%02s', dechex($r)) . sprintf('%02s', dechex($g)) . sprintf('%02s', dechex($b)); } else { $font_size = 0; } if ($font_size >= $fmin) { $cloud .= "<span style=\"font-size: {$font_size}px; color: $color;\">$word</span> "; $tags++; } } $cloud .= "</div>"; return array($cloud, $tags); } $words = ['una' => 2, 'dos' => 2, '3' => 3]; var_dump(word_cloud($words));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/05CEX
function name:  (null)
number of ops:  8
compiled vars:  !0 = $words
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   ASSIGN                                                   !0, <array>
   51     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'word_cloud'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function word_cloud:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 77
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 77
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 64
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 76
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 76
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 76
Branch analysis from position: 67
Branch analysis from position: 76
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
filename:       /in/05CEX
function name:  word_cloud
number of ops:  83
compiled vars:  !0 = $words, !1 = $div_size, !2 = $tags, !3 = $cloud, !4 = $fmax, !5 = $fmin, !6 = $tmin, !7 = $tmax, !8 = $frequency, !9 = $word, !10 = $font_size, !11 = $r, !12 = $g, !13 = $b, !14 = $color
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      400
    5     2        ASSIGN                                                   !2, 0
    6     3        ROPE_INIT                                     3  ~17     '%3Cdiv+style%3D%22width%3A+'
          4        ROPE_ADD                                      1  ~17     ~17, !1
          5        ROPE_END                                      2  ~16     ~17, 'px%22%3E'
          6        ASSIGN                                                   !3, ~16
   12     7        ASSIGN                                                   !4, 96
   13     8        ASSIGN                                                   !5, 8
   14     9        INIT_FCALL                                               'min'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $22     
         12        ASSIGN                                                   !6, $22
   15    13        INIT_FCALL                                               'max'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $24     
         16        ASSIGN                                                   !7, $24
   17    17      > FE_RESET_R                                       $26     !0, ->77
         18    > > FE_FETCH_R                                       ~27     $26, !8, ->77
         19    >   ASSIGN                                                   !9, ~27
   19    20        IS_SMALLER                                               !6, !8
         21      > JMPZ                                                     ~29, ->64
   20    22    >   INIT_FCALL                                               'floor'
         23        SUB                                              ~30     !8, !6
         24        MUL                                              ~31     !4, ~30
         25        SUB                                              ~32     !7, !6
         26        DIV                                              ~33     ~31, ~32
         27        SEND_VAL                                                 ~33
         28        DO_ICALL                                         $34     
         29        ASSIGN                                                   !10, $34
   22    30        ASSIGN                                           ~36     !12, 0
         31        ASSIGN                                                   !11, ~36
         32        INIT_FCALL                                               'floor'
         33        DIV                                              ~38     !8, !7
         34        MUL                                              ~39     ~38, 255
         35        SEND_VAL                                                 ~39
         36        DO_ICALL                                         $40     
         37        ASSIGN                                                   !13, $40
   23    38        INIT_FCALL                                               'sprintf'
         39        SEND_VAL                                                 '%2502s'
         40        INIT_FCALL                                               'dechex'
         41        SEND_VAR                                                 !11
         42        DO_ICALL                                         $42     
         43        SEND_VAR                                                 $42
         44        DO_ICALL                                         $43     
         45        CONCAT                                           ~44     '%23', $43
         46        INIT_FCALL                                               'sprintf'
         47        SEND_VAL                                                 '%2502s'
         48        INIT_FCALL                                               'dechex'
         49        SEND_VAR                                                 !12
         50        DO_ICALL                                         $45     
         51        SEND_VAR                                                 $45
         52        DO_ICALL                                         $46     
         53        CONCAT                                           ~47     ~44, $46
         54        INIT_FCALL                                               'sprintf'
         55        SEND_VAL                                                 '%2502s'
         56        INIT_FCALL                                               'dechex'
         57        SEND_VAR                                                 !13
         58        DO_ICALL                                         $48     
         59        SEND_VAR                                                 $48
         60        DO_ICALL                                         $49     
         61        CONCAT                                           ~50     ~47, $49
         62        ASSIGN                                                   !14, ~50
         63      > JMP                                                      ->65
   26    64    >   ASSIGN                                                   !10, 0
   29    65    >   IS_SMALLER_OR_EQUAL                                      !5, !10
         66      > JMPZ                                                     ~53, ->76
   30    67    >   ROPE_INIT                                     7  ~55     '%3Cspan+style%3D%22font-size%3A+'
         68        ROPE_ADD                                      1  ~55     ~55, !10
         69        ROPE_ADD                                      2  ~55     ~55, 'px%3B+color%3A+'
         70        ROPE_ADD                                      3  ~55     ~55, !14
         71        ROPE_ADD                                      4  ~55     ~55, '%3B%22%3E'
         72        ROPE_ADD                                      5  ~55     ~55, !9
         73        ROPE_END                                      6  ~54     ~55, '%3C%2Fspan%3E+'
         74        ASSIGN_OP                                     8          !3, ~54
   31    75        PRE_INC                                                  !2
   17    76    > > JMP                                                      ->18
         77    >   FE_FREE                                                  $26
   36    78        ASSIGN_OP                                     8          !3, '%3C%2Fdiv%3E'
   38    79        INIT_ARRAY                                       ~62     !3
         80        ADD_ARRAY_ELEMENT                                ~62     !2
         81      > RETURN                                                   ~62
   40    82*     > RETURN                                                   null

End of function word_cloud

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.32 ms | 1407 KiB | 26 Q