3v4l.org

run code in 300+ PHP versions simultaneously
<?php $products = [1, 2, 3, 4, 5]; $vendors = ["Amazon", "Newegg", "##php"]; // Super complex price calculator function getPrice($vendor, $product) { return rand(0, 100); } $productsCalculated = []; $chosenVendors = []; foreach ($products as $productID) { $prices = []; foreach ($vendors as $vendor) { $prices[$vendor] = getPrice($vendor, $productID); } sort($prices); // Save this for debugging $productsCalculated[$productID] = $prices; // Retreive the first item of the array as it should be lowest reset($prices); $chosenVendor = key($prices); var_dump($chosenVendor); $chosenVendors[$chosenVendor][] = $productID; } var_dump($productsCalculated); var_dump($chosenVendors);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 36
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 36
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/RDL86
function name:  (null)
number of ops:  44
compiled vars:  !0 = $products, !1 = $vendors, !2 = $productsCalculated, !3 = $chosenVendors, !4 = $productID, !5 = $prices, !6 = $vendor, !7 = $chosenVendor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
   11     2        ASSIGN                                                   !2, <array>
   12     3        ASSIGN                                                   !3, <array>
   14     4      > FE_RESET_R                                       $12     !0, ->36
          5    > > FE_FETCH_R                                               $12, !4, ->36
   15     6    >   ASSIGN                                                   !5, <array>
   17     7      > FE_RESET_R                                       $14     !1, ->16
          8    > > FE_FETCH_R                                               $14, !6, ->16
   18     9    >   INIT_FCALL                                               'getprice'
         10        SEND_VAR                                                 !6
         11        SEND_VAR                                                 !4
         12        DO_FCALL                                      0  $16     
         13        ASSIGN_DIM                                               !5, !6
         14        OP_DATA                                                  $16
   17    15      > JMP                                                      ->8
         16    >   FE_FREE                                                  $14
   21    17        INIT_FCALL                                               'sort'
         18        SEND_REF                                                 !5
         19        DO_ICALL                                                 
   24    20        ASSIGN_DIM                                               !2, !4
         21        OP_DATA                                                  !5
   27    22        INIT_FCALL                                               'reset'
         23        SEND_REF                                                 !5
         24        DO_ICALL                                                 
   28    25        INIT_FCALL                                               'key'
         26        SEND_VAR                                                 !5
         27        DO_ICALL                                         $20     
         28        ASSIGN                                                   !7, $20
   29    29        INIT_FCALL                                               'var_dump'
         30        SEND_VAR                                                 !7
         31        DO_ICALL                                                 
   31    32        FETCH_DIM_W                                      $23     !3, !7
         33        ASSIGN_DIM                                               $23
         34        OP_DATA                                                  !4
   14    35      > JMP                                                      ->5
         36    >   FE_FREE                                                  $12
   34    37        INIT_FCALL                                               'var_dump'
         38        SEND_VAR                                                 !2
         39        DO_ICALL                                                 
   35    40        INIT_FCALL                                               'var_dump'
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Function getprice:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RDL86
function name:  getPrice
number of ops:  8
compiled vars:  !0 = $vendor, !1 = $product
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_FCALL                                               'rand'
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 100
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
    9     7*     > RETURN                                                   null

End of function getprice

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.27 ms | 1403 KiB | 24 Q