3v4l.org

run code in 300+ PHP versions simultaneously
<?php function tryDistributeLinksEvenly($howManyMessages, $links){ echo "testing $howManyMessages\n"; $messages = array_chunk($links, $howManyMessages, true); $count = 0; 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/m0Lg4
function name:  (null)
number of ops:  10
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, <array>
   46     1        INIT_FCALL                                               'array_combine'
          2        SEND_VAR                                                 !0
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !0, $2
   47     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 = 14, Position 2 = 30
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 30
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/m0Lg4
function name:  tryDistributeLinksEvenly
number of ops:  33
compiled vars:  !0 = $howManyMessages, !1 = $links, !2 = $messages, !3 = $count, !4 = $message
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        ASSIGN                                                   !3, 0
    8    13      > FE_RESET_R                                       $11     !2, ->30
         14    > > FE_FETCH_R                                               $11, !4, ->30
    9    15    >   INIT_FCALL                                               'array_reduce'
         16        INIT_FCALL                                               'array_keys'
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                         $12     
         19        SEND_VAR                                                 $12
         20        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fm0Lg4%3A9%240'
         21        SEND_VAL                                                 ~13
         22        DO_ICALL                                         $14     
         23        ASSIGN_OP                                     1          !3, $14
   10    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                                 
   11    27        CONCAT                                           ~17     !3, '%0A'
         28        ECHO                                                     ~17
    8    29      > JMP                                                      ->14
         30    >   FE_FREE                                                  $11
   13    31        ECHO                                                     '-----%0A'
   14    32      > RETURN                                                   null

End of function trydistributelinksevenly

Function %00%7Bclosure%7D%2Fin%2Fm0Lg4%3A9%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m0Lg4
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     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%2Fm0Lg4%3A9%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/m0Lg4
function name:  distributeLinksEvenly
number of ops:  15
compiled vars:  !0 = $links, !1 = $howManyMessages, !2 = $chunks
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ASSIGN                                                   !1, 0
   19     2    >   PRE_INC                                                  !1
   20     3        INIT_FCALL                                               'trydistributelinksevenly'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !2, $5
   21     8        IS_SMALLER                                               10, !1
          9      > JMPZ                                                     ~7, ->11
         10    > > EXIT                                                     
   22    11    >   TYPE_CHECK                                    2          !2
         12      > JMPNZ                                                    ~8, ->2
   23    13    > > RETURN                                                   !2
   24    14*     > RETURN                                                   null

End of function distributelinksevenly

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.69 ms | 1407 KiB | 27 Q