3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splitItems(array $limits, int $total): array { asort($limits); foreach ($limits as &$limit) { $limit = min($limit, $total); $total -= $limit; } ksort($limits); return $limits; } var_export(splitItems([14, 2], 10)); echo "\n---\n"; var_export(splitItems([6, 8, 2], 14)); echo "\n---\n"; var_export(splitItems([6, 4, 2], 14)); echo "\n---\n"; var_export(splitItems([7, 7, 1], 4)); echo "\n---\n"; var_export(splitItems([1, 1], 10)); echo "\n---\n"; var_export(splitItems([2,1,3],4));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iTVPj
function name:  (null)
number of ops:  48
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'var_export'
          1        INIT_FCALL                                               'splititems'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 10
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   14     7        ECHO                                                     '%0A---%0A'
   15     8        INIT_FCALL                                               'var_export'
          9        INIT_FCALL                                               'splititems'
         10        SEND_VAL                                                 <array>
         11        SEND_VAL                                                 14
         12        DO_FCALL                                      0  $2      
         13        SEND_VAR                                                 $2
         14        DO_ICALL                                                 
   16    15        ECHO                                                     '%0A---%0A'
   17    16        INIT_FCALL                                               'var_export'
         17        INIT_FCALL                                               'splititems'
         18        SEND_VAL                                                 <array>
         19        SEND_VAL                                                 14
         20        DO_FCALL                                      0  $4      
         21        SEND_VAR                                                 $4
         22        DO_ICALL                                                 
   18    23        ECHO                                                     '%0A---%0A'
   19    24        INIT_FCALL                                               'var_export'
         25        INIT_FCALL                                               'splititems'
         26        SEND_VAL                                                 <array>
         27        SEND_VAL                                                 4
         28        DO_FCALL                                      0  $6      
         29        SEND_VAR                                                 $6
         30        DO_ICALL                                                 
   20    31        ECHO                                                     '%0A---%0A'
   21    32        INIT_FCALL                                               'var_export'
         33        INIT_FCALL                                               'splititems'
         34        SEND_VAL                                                 <array>
         35        SEND_VAL                                                 10
         36        DO_FCALL                                      0  $8      
         37        SEND_VAR                                                 $8
         38        DO_ICALL                                                 
   22    39        ECHO                                                     '%0A---%0A'
   23    40        INIT_FCALL                                               'var_export'
         41        INIT_FCALL                                               'splititems'
         42        SEND_VAL                                                 <array>
         43        SEND_VAL                                                 4
         44        DO_FCALL                                      0  $10     
         45        SEND_VAR                                                 $10
         46        DO_ICALL                                                 
         47      > RETURN                                                   1

Function splititems:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 126) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/iTVPj
function name:  splitItems
number of ops:  22
compiled vars:  !0 = $limits, !1 = $total, !2 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'asort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
    5     5      > FE_RESET_RW                                      $4      !0, ->14
          6    > > FE_FETCH_RW                                              $4, !2, ->14
    6     7    >   INIT_FCALL                                               'min'
          8        SEND_VAR                                                 !2
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $5      
         11        ASSIGN                                                   !2, $5
    7    12        ASSIGN_OP                                     2          !1, !2
    5    13      > JMP                                                      ->6
         14    >   FE_FREE                                                  $4
    9    15        INIT_FCALL                                               'ksort'
         16        SEND_REF                                                 !0
         17        DO_ICALL                                                 
   10    18        VERIFY_RETURN_TYPE                                       !0
         19      > RETURN                                                   !0
   11    20*       VERIFY_RETURN_TYPE                                       
         21*     > RETURN                                                   null

End of function splititems

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.42 ms | 1021 KiB | 23 Q