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 = [ 'Cala', 'Ya', 'Ocean', 'Chaba', ]; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } $starCoefOptions = range(0.1, 5, 0.1); $ratingCoefOptions = range(20, 10000, 20); $results = []; foreach ( $starCoefOptions as $starCoef ) { foreach ( $ratingCoefOptions as $ratingCoef ) { $topGenerated = buildTop($hotels, $starCoef, $ratingCoef); $topGenerated = array_slice($topGenerated, 0, count($top)); if ( $topGenerated === $top ) { $results[strval($starCoef)][] = $ratingCoef; } } } foreach ( $results as $starCoef=>$ratingCoefs ) { echo $starCoef.': '.min($ratingCoefs).' - '.max($ratingCoefs)."\r\n"; } 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
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 50
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 50
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 48
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 48
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 47
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 47
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 48
Branch analysis from position: 50
2 jumps found. (Code = 77) Position 1 = 52, Position 2 = 67
Branch analysis from position: 52
2 jumps found. (Code = 78) Position 1 = 53, Position 2 = 67
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
Branch analysis from position: 50
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/nup6v
function name:  (null)
number of ops:  69
compiled vars:  !0 = $hotels, !1 = $top, !2 = $i, !3 = $starCoefOptions, !4 = $ratingCoefOptions, !5 = $results, !6 = $starCoef, !7 = $ratingCoef, !8 = $topGenerated, !9 = $ratingCoefs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->8
   19     4    >   FETCH_DIM_W                                      $13     !0, !2
          5        ASSIGN_DIM                                               $13, 4
          6        OP_DATA                                                  0
   18     7        PRE_INC                                                  !2
          8    >   COUNT                                            ~16     !0
          9        IS_SMALLER                                               !2, ~16
         10      > JMPNZ                                                    ~17, ->4
   22    11    >   INIT_FCALL                                               'range'
         12        SEND_VAL                                                 0.1
         13        SEND_VAL                                                 5
         14        SEND_VAL                                                 0.1
         15        DO_ICALL                                         $18     
         16        ASSIGN                                                   !3, $18
   23    17        INIT_FCALL                                               'range'
         18        SEND_VAL                                                 20
         19        SEND_VAL                                                 10000
         20        SEND_VAL                                                 20
         21        DO_ICALL                                         $20     
         22        ASSIGN                                                   !4, $20
   25    23        ASSIGN                                                   !5, <array>
   27    24      > FE_RESET_R                                       $23     !3, ->50
         25    > > FE_FETCH_R                                               $23, !6, ->50
   28    26    > > FE_RESET_R                                       $24     !4, ->48
         27    > > FE_FETCH_R                                               $24, !7, ->48
   29    28    >   INIT_FCALL_BY_NAME                                       'buildTop'
         29        SEND_VAR_EX                                              !0
         30        SEND_VAR_EX                                              !6
         31        SEND_VAR_EX                                              !7
         32        DO_FCALL                                      0  $25     
         33        ASSIGN                                                   !8, $25
   30    34        INIT_FCALL                                               'array_slice'
         35        SEND_VAR                                                 !8
         36        SEND_VAL                                                 0
         37        COUNT                                            ~27     !1
         38        SEND_VAL                                                 ~27
         39        DO_ICALL                                         $28     
         40        ASSIGN                                                   !8, $28
   31    41        IS_IDENTICAL                                             !8, !1
         42      > JMPZ                                                     ~30, ->47
   32    43    >   CAST                                          6  ~31     !6
         44        FETCH_DIM_W                                      $32     !5, ~31
         45        ASSIGN_DIM                                               $32
         46        OP_DATA                                                  !7
   28    47    > > JMP                                                      ->27
         48    >   FE_FREE                                                  $24
   27    49      > JMP                                                      ->25
         50    >   FE_FREE                                                  $23
   37    51      > FE_RESET_R                                       $34     !5, ->67
         52    > > FE_FETCH_R                                       ~35     $34, !9, ->67
         53    >   ASSIGN                                                   !6, ~35
   38    54        CONCAT                                           ~37     !6, '%3A+'
         55        INIT_FCALL                                               'min'
         56        SEND_VAR                                                 !9
         57        DO_ICALL                                         $38     
         58        CONCAT                                           ~39     ~37, $38
         59        CONCAT                                           ~40     ~39, '+-+'
         60        INIT_FCALL                                               'max'
         61        SEND_VAR                                                 !9
         62        DO_ICALL                                         $41     
         63        CONCAT                                           ~42     ~40, $41
         64        CONCAT                                           ~43     ~42, '%0D%0A'
         65        ECHO                                                     ~43
   37    66      > JMP                                                      ->52
         67    >   FE_FREE                                                  $34
   68    68      > 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/nup6v
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
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   43     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->50
   44     5    >   ADD                                              ~12     !3, 1
          6        ASSIGN                                                   !4, ~12
          7      > JMP                                                      ->46
   45     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
   46    14        MUL                                              ~20     !5, !1
         15        ASSIGN                                                   !6, ~20
   47    16        FETCH_DIM_R                                      ~22     !0, !3
         17        FETCH_DIM_R                                      ~23     ~22, 2
         18        ADD                                              ~24     ~23, !6
         19        ASSIGN                                                   !7, ~24
   49    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
   50    25        MUL                                              ~31     !8, !2
         26        ASSIGN                                                   !9, ~31
   51    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
   53    34        FETCH_DIM_R                                      ~38     !0, !4
         35        FETCH_DIM_R                                      ~39     ~38, 3
         36        IS_SMALLER                                               !10, ~39
         37      > JMPZ                                                     ~40, ->42
   54    38    >   FETCH_DIM_RW                                     $41     !0, !3
         39        FETCH_DIM_RW                                     $42     $41, 4
         40        PRE_INC                                                  $42
         41      > JMP                                                      ->45
   56    42    >   FETCH_DIM_RW                                     $44     !0, !4
         43        FETCH_DIM_RW                                     $45     $44, 4
         44        PRE_INC                                                  $45
   44    45    >   PRE_INC                                                  !4
         46    >   COUNT                                            ~48     !0
         47        IS_SMALLER                                               !4, ~48
         48      > JMPNZ                                                    ~49, ->8
   43    49    >   PRE_INC                                                  !3
         50    >   COUNT                                            ~51     !0
         51        IS_SMALLER                                               !3, ~51
         52      > JMPNZ                                                    ~52, ->5
   61    53    >   INIT_FCALL                                               'usort'
         54        SEND_REF                                                 !0
         55        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fnup6v%3A61%240'
   63    56        SEND_VAL                                                 ~53
         57        DO_ICALL                                                 
   65    58        INIT_FCALL                                               'array_map'
         59        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fnup6v%3A65%241'
   67    60        SEND_VAL                                                 ~55
         61        SEND_VAR                                                 !0
         62        DO_ICALL                                         $56     
         63      > RETURN                                                   $56
   68    64*     > RETURN                                                   null

End of function buildtop

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

End of function %00%7Bclosure%7D%2Fin%2Fnup6v%3A61%240

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

End of function %00%7Bclosure%7D%2Fin%2Fnup6v%3A65%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.15 ms | 1412 KiB | 27 Q