3v4l.org

run code in 300+ PHP versions simultaneously
<?php function fill_packages( $packages ) { $overrun = 42; // Items in cart $cost = 0; $filled = array(); $quantities = array(); foreach( $packages as $the_package ){ $delivers = floor( $overrun / $the_package['contain'] ); if( ! $delivers ) { continue; } $filled[$the_package['name']] = $delivers; $overrun = $overrun - ( $delivers * $the_package['contain'] ); $cost = $cost + ( $delivers * $the_package['cost'] ); } if( $overrun ) { return 'Error, Overrun of ' . $overrun . '!'; } return array( 'packages' => $filled, 'cost' => $cost, ); } /* Test it! */ print_r( fill_packages( array( array( 'name' => '18er', 'contain' => 18, 'cost' => 5 ), array( 'name' => '12er', 'contain' => 12, 'cost' => 5 ), array( 'name' => '6er', 'contain' => 6, 'cost' => 8 ), ) ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uoILt
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'print_r'
   29     1        INIT_FCALL                                               'fill_packages'
   32     2        SEND_VAL                                                 <array>
   29     3        DO_FCALL                                      0  $0      
   32     4        SEND_VAR                                                 $0
   28     5        DO_ICALL                                                 
   48     6      > RETURN                                                   1

Function fill_packages:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 28
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 28
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 33
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/uoILt
function name:  fill_packages
number of ops:  37
compiled vars:  !0 = $packages, !1 = $overrun, !2 = $cost, !3 = $filled, !4 = $quantities, !5 = $the_package, !6 = $delivers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, 42
    5     2        ASSIGN                                                   !2, 0
    6     3        ASSIGN                                                   !3, <array>
    7     4        ASSIGN                                                   !4, <array>
    8     5      > FE_RESET_R                                       $11     !0, ->28
          6    > > FE_FETCH_R                                               $11, !5, ->28
    9     7    >   INIT_FCALL                                               'floor'
          8        FETCH_DIM_R                                      ~12     !5, 'contain'
          9        DIV                                              ~13     !1, ~12
         10        SEND_VAL                                                 ~13
         11        DO_ICALL                                         $14     
         12        ASSIGN                                                   !6, $14
   10    13        BOOL_NOT                                         ~16     !6
         14      > JMPZ                                                     ~16, ->16
   11    15    > > JMP                                                      ->6
   13    16    >   FETCH_DIM_R                                      ~17     !5, 'name'
         17        ASSIGN_DIM                                               !3, ~17
         18        OP_DATA                                                  !6
   14    19        FETCH_DIM_R                                      ~19     !5, 'contain'
         20        MUL                                              ~20     !6, ~19
         21        SUB                                              ~21     !1, ~20
         22        ASSIGN                                                   !1, ~21
   15    23        FETCH_DIM_R                                      ~23     !5, 'cost'
         24        MUL                                              ~24     !6, ~23
         25        ADD                                              ~25     !2, ~24
         26        ASSIGN                                                   !2, ~25
    8    27      > JMP                                                      ->6
         28    >   FE_FREE                                                  $11
   17    29      > JMPZ                                                     !1, ->33
   18    30    >   CONCAT                                           ~27     'Error%2C+Overrun+of+', !1
         31        CONCAT                                           ~28     ~27, '%21'
         32      > RETURN                                                   ~28
   21    33    >   INIT_ARRAY                                       ~29     !3, 'packages'
   22    34        ADD_ARRAY_ELEMENT                                ~29     !2, 'cost'
         35      > RETURN                                                   ~29
   24    36*     > RETURN                                                   null

End of function fill_packages

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.76 ms | 1010 KiB | 16 Q