3v4l.org

run code in 300+ PHP versions simultaneously
<?php $hotels = [ ['Cala', 3, 8.7, 6000], ['Ocean', 3, 8.2, 6150], ['Orchid', 3, 8.0, 7200], ['Ya', 4, 8.3, 6950], ['Chaba', 3, 8.2, 7120], ]; $top = [ 'Ocean', 'Ya', 'Chaba', ]; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } var_dump(buildTop($hotels, 0.2, 2000)); function buildTop($hotels, $starCoef, $ratingCoef) { for ( $i=0; $i<count($hotels); $i++ ) { for ( $j=$i+1; $j<count($hotels); $j++ ) { $starDifference = $hotels[$i][1]-$hotels[$j][1]; $ratingToCompensate = $starDifference*$starCoef; $rating = $hotels[$i][2]+$ratingToCompensate; $ratingDifference = ($rating-$hotels[$j][2])*10; $priceToCompensate = $ratingDifference*$ratingCoef; $price = round($hotels[$i][3]-$priceToCompensate); if ( $price < $hotels[$j][3] ) { $hotels[$i][4]++; } else { $hotels[$j][4]++; } } } usort($hotels, function($hotelA, $hotelB){ return $hotelB[4]-$hotelA[4]; }); return array_map(function($hotel){ return $hotel[0]; }, $hotels); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
Branch analysis from position: 4
filename:       /in/1DDCU
function name:  (null)
number of ops:  20
compiled vars:  !0 = $hotels, !1 = $top, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   17     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->8
   18     4    >   FETCH_DIM_W                                      $6      !0, !2
          5        ASSIGN_DIM                                               $6, 4
          6        OP_DATA                                                  0
   17     7        PRE_INC                                                  !2
          8    >   COUNT                                            ~9      !0
          9        IS_SMALLER                                               !2, ~9
         10      > JMPNZ                                                    ~10, ->4
   21    11    >   INIT_FCALL                                               'var_dump'
         12        INIT_FCALL_BY_NAME                                       'buildTop'
         13        SEND_VAR_EX                                              !0
         14        SEND_VAL_EX                                              0.2
         15        SEND_VAL_EX                                              2000
         16        DO_FCALL                                      0  $11     
         17        SEND_VAR                                                 $11
         18        DO_ICALL                                                 
   50    19      > RETURN                                                   1

Function buildtop:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 5
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 8
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 5
Branch analysis from position: 53
Branch analysis from position: 5
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 42
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 8
Branch analysis from position: 49
Branch analysis from position: 8
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 8
Branch analysis from position: 49
Branch analysis from position: 8
filename:       /in/1DDCU
function name:  buildTop
number of ops:  65
compiled vars:  !0 = $hotels, !1 = $starCoef, !2 = $ratingCoef, !3 = $i, !4 = $j, !5 = $starDifference, !6 = $ratingToCompensate, !7 = $rating, !8 = $ratingDifference, !9 = $priceToCompensate, !10 = $price
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   25     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->50
   26     5    >   ADD                                              ~12     !3, 1
          6        ASSIGN                                                   !4, ~12
          7      > JMP                                                      ->46
   27     8    >   FETCH_DIM_R                                      ~14     !0, !3
          9        FETCH_DIM_R                                      ~15     ~14, 1
         10        FETCH_DIM_R                                      ~16     !0, !4
         11        FETCH_DIM_R                                      ~17     ~16, 1
         12        SUB                                              ~18     ~15, ~17
         13        ASSIGN                                                   !5, ~18
   28    14        MUL                                              ~20     !5, !1
         15        ASSIGN                                                   !6, ~20
   29    16        FETCH_DIM_R                                      ~22     !0, !3
         17        FETCH_DIM_R                                      ~23     ~22, 2
         18        ADD                                              ~24     ~23, !6
         19        ASSIGN                                                   !7, ~24
   31    20        FETCH_DIM_R                                      ~26     !0, !4
         21        FETCH_DIM_R                                      ~27     ~26, 2
         22        SUB                                              ~28     !7, ~27
         23        MUL                                              ~29     ~28, 10
         24        ASSIGN                                                   !8, ~29
   32    25        MUL                                              ~31     !8, !2
         26        ASSIGN                                                   !9, ~31
   33    27        INIT_FCALL                                               'round'
         28        FETCH_DIM_R                                      ~33     !0, !3
         29        FETCH_DIM_R                                      ~34     ~33, 3
         30        SUB                                              ~35     ~34, !9
         31        SEND_VAL                                                 ~35
         32        DO_ICALL                                         $36     
         33        ASSIGN                                                   !10, $36
   35    34        FETCH_DIM_R                                      ~38     !0, !4
         35        FETCH_DIM_R                                      ~39     ~38, 3
         36        IS_SMALLER                                               !10, ~39
         37      > JMPZ                                                     ~40, ->42
   36    38    >   FETCH_DIM_RW                                     $41     !0, !3
         39        FETCH_DIM_RW                                     $42     $41, 4
         40        PRE_INC                                                  $42
         41      > JMP                                                      ->45
   38    42    >   FETCH_DIM_RW                                     $44     !0, !4
         43        FETCH_DIM_RW                                     $45     $44, 4
         44        PRE_INC                                                  $45
   26    45    >   PRE_INC                                                  !4
         46    >   COUNT                                            ~48     !0
         47        IS_SMALLER                                               !4, ~48
         48      > JMPNZ                                                    ~49, ->8
   25    49    >   PRE_INC                                                  !3
         50    >   COUNT                                            ~51     !0
         51        IS_SMALLER                                               !3, ~51
         52      > JMPNZ                                                    ~52, ->5
   43    53    >   INIT_FCALL                                               'usort'
         54        SEND_REF                                                 !0
         55        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1DDCU%3A43%240'
   45    56        SEND_VAL                                                 ~53
         57        DO_ICALL                                                 
   47    58        INIT_FCALL                                               'array_map'
         59        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1DDCU%3A47%241'
   49    60        SEND_VAL                                                 ~55
         61        SEND_VAR                                                 !0
         62        DO_ICALL                                         $56     
         63      > RETURN                                                   $56
   50    64*     > RETURN                                                   null

End of function buildtop

Function %00%7Bclosure%7D%2Fin%2F1DDCU%3A43%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1DDCU
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $hotelA, !1 = $hotelB
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   44     2        FETCH_DIM_R                                      ~2      !1, 4
          3        FETCH_DIM_R                                      ~3      !0, 4
          4        SUB                                              ~4      ~2, ~3
          5      > RETURN                                                   ~4
   45     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1DDCU%3A43%240

Function %00%7Bclosure%7D%2Fin%2F1DDCU%3A47%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1DDCU
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $hotel
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        FETCH_DIM_R                                      ~1      !0, 0
          2      > RETURN                                                   ~1
   49     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1DDCU%3A47%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.1 ms | 1404 KiB | 21 Q