3v4l.org

run code in 300+ PHP versions simultaneously
<?php function tryDistributeLinksEvenly($howManyMessages, $links){ echo "testing $howManyMessages\n"; $messages = array_chunk($links, $howManyMessages, true); foreach($messages as $message){ $count = array_reduce(array_keys($message), function($a, $b){ return mb_strlen($a) + mb_strlen($b) + 2; }); var_dump($message); echo $count . "\n"; } echo "-----\n"; } function distributeLinksEvenly($links){ $howManyMessages = 0; do{ $howManyMessages++; $chunks = tryDistributeLinksEvenly($howManyMessages, $links); if($howManyMessages > 10) exit(); }while($chunks === null); return $chunks; } $v = [ 'aaaa', 'bbbb', 'ccccccc', 'dddddddddd', 'eeeeeeee', 'ffffffffffff', 'gggg', 'hhhhhh', 'iiiiiiiiiii', 'lllllll', 'mmmmmmmmmmm', 'nnnnnnn', 'ooo', ]; $v = array_combine($v, $v); distributeLinksEvenly($v);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/udqg5
function name:  (null)
number of ops:  10
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   ASSIGN                                                   !0, <array>
   45     1        INIT_FCALL                                               'array_combine'
          2        SEND_VAR                                                 !0
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !0, $2
   46     6        INIT_FCALL                                               'distributelinksevenly'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0          
          9      > RETURN                                                   1

Function trydistributelinksevenly:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 29
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 29
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/udqg5
function name:  tryDistributeLinksEvenly
number of ops:  32
compiled vars:  !0 = $howManyMessages, !1 = $links, !2 = $messages, !3 = $message, !4 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ROPE_INIT                                     3  ~6      'testing+'
          3        ROPE_ADD                                      1  ~6      ~6, !0
          4        ROPE_END                                      2  ~5      ~6, '%0A'
          5        ECHO                                                     ~5
    6     6        INIT_FCALL                                               'array_chunk'
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !2, $8
    7    12      > FE_RESET_R                                       $10     !2, ->29
         13    > > FE_FETCH_R                                               $10, !3, ->29
    8    14    >   INIT_FCALL                                               'array_reduce'
         15        INIT_FCALL                                               'array_keys'
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $11     
         18        SEND_VAR                                                 $11
         19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fudqg5%3A8%240'
         20        SEND_VAL                                                 ~12
         21        DO_ICALL                                         $13     
         22        ASSIGN                                                   !4, $13
    9    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                                 
   10    26        CONCAT                                           ~16     !4, '%0A'
         27        ECHO                                                     ~16
    7    28      > JMP                                                      ->13
         29    >   FE_FREE                                                  $10
   12    30        ECHO                                                     '-----%0A'
   13    31      > RETURN                                                   null

End of function trydistributelinksevenly

Function %00%7Bclosure%7D%2Fin%2Fudqg5%3A8%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/udqg5
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'mb_strlen'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        INIT_FCALL                                               'mb_strlen'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $3      
          8        ADD                                              ~4      $2, $3
          9        ADD                                              ~5      ~4, 2
         10      > RETURN                                                   ~5
         11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fudqg5%3A8%240

Function distributelinksevenly:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
filename:       /in/udqg5
function name:  distributeLinksEvenly
number of ops:  15
compiled vars:  !0 = $links, !1 = $howManyMessages, !2 = $chunks
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        ASSIGN                                                   !1, 0
   18     2    >   PRE_INC                                                  !1
   19     3        INIT_FCALL                                               'trydistributelinksevenly'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !2, $5
   20     8        IS_SMALLER                                               10, !1
          9      > JMPZ                                                     ~7, ->11
         10    > > EXIT                                                     
   21    11    >   TYPE_CHECK                                    2          !2
         12      > JMPNZ                                                    ~8, ->2
   22    13    > > RETURN                                                   !2
   23    14*     > RETURN                                                   null

End of function distributelinksevenly

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.62 ms | 1407 KiB | 27 Q