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', 'Ocean', 'Ya', ]; 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[$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 = 49
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 49
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 47
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 47
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 46
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 47
Branch analysis from position: 49
2 jumps found. (Code = 77) Position 1 = 51, Position 2 = 66
Branch analysis from position: 51
2 jumps found. (Code = 78) Position 1 = 52, Position 2 = 66
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
Branch analysis from position: 49
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/YANU6
function name:  (null)
number of ops:  68
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>
   17     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->8
   18     4    >   FETCH_DIM_W                                      $13     !0, !2
          5        ASSIGN_DIM                                               $13, 4
          6        OP_DATA                                                  0
   17     7        PRE_INC                                                  !2
          8    >   COUNT                                            ~16     !0
          9        IS_SMALLER                                               !2, ~16
         10      > JMPNZ                                                    ~17, ->4
   21    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
   22    17        INIT_FCALL                                               'range'
         18        SEND_VAL                                                 20
         19        SEND_VAL                                                 10000
         20        SEND_VAL                                                 20
         21        DO_ICALL                                         $20     
         22        ASSIGN                                                   !4, $20
   24    23        ASSIGN                                                   !5, <array>
   26    24      > FE_RESET_R                                       $23     !3, ->49
         25    > > FE_FETCH_R                                               $23, !6, ->49
   27    26    > > FE_RESET_R                                       $24     !4, ->47
         27    > > FE_FETCH_R                                               $24, !7, ->47
   28    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
   29    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
   30    41        IS_IDENTICAL                                             !8, !1
         42      > JMPZ                                                     ~30, ->46
   31    43    >   FETCH_DIM_W                                      $31     !5, !6
         44        ASSIGN_DIM                                               $31
         45        OP_DATA                                                  !7
   27    46    > > JMP                                                      ->27
         47    >   FE_FREE                                                  $24
   26    48      > JMP                                                      ->25
         49    >   FE_FREE                                                  $23
   36    50      > FE_RESET_R                                       $33     !5, ->66
         51    > > FE_FETCH_R                                       ~34     $33, !9, ->66
         52    >   ASSIGN                                                   !6, ~34
   37    53        CONCAT                                           ~36     !6, '%3A+'
         54        INIT_FCALL                                               'min'
         55        SEND_VAR                                                 !9
         56        DO_ICALL                                         $37     
         57        CONCAT                                           ~38     ~36, $37
         58        CONCAT                                           ~39     ~38, '+-+'
         59        INIT_FCALL                                               'max'
         60        SEND_VAR                                                 !9
         61        DO_ICALL                                         $40     
         62        CONCAT                                           ~41     ~39, $40
         63        CONCAT                                           ~42     ~41, '%0D%0A'
         64        ECHO                                                     ~42
   36    65      > JMP                                                      ->51
         66    >   FE_FREE                                                  $33
   67    67      > 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/YANU6
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
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   42     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->50
   43     5    >   ADD                                              ~12     !3, 1
          6        ASSIGN                                                   !4, ~12
          7      > JMP                                                      ->46
   44     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
   45    14        MUL                                              ~20     !5, !1
         15        ASSIGN                                                   !6, ~20
   46    16        FETCH_DIM_R                                      ~22     !0, !3
         17        FETCH_DIM_R                                      ~23     ~22, 2
         18        ADD                                              ~24     ~23, !6
         19        ASSIGN                                                   !7, ~24
   48    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
   49    25        MUL                                              ~31     !8, !2
         26        ASSIGN                                                   !9, ~31
   50    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
   52    34        FETCH_DIM_R                                      ~38     !0, !4
         35        FETCH_DIM_R                                      ~39     ~38, 3
         36        IS_SMALLER                                               !10, ~39
         37      > JMPZ                                                     ~40, ->42
   53    38    >   FETCH_DIM_RW                                     $41     !0, !3
         39        FETCH_DIM_RW                                     $42     $41, 4
         40        PRE_INC                                                  $42
         41      > JMP                                                      ->45
   55    42    >   FETCH_DIM_RW                                     $44     !0, !4
         43        FETCH_DIM_RW                                     $45     $44, 4
         44        PRE_INC                                                  $45
   43    45    >   PRE_INC                                                  !4
         46    >   COUNT                                            ~48     !0
         47        IS_SMALLER                                               !4, ~48
         48      > JMPNZ                                                    ~49, ->8
   42    49    >   PRE_INC                                                  !3
         50    >   COUNT                                            ~51     !0
         51        IS_SMALLER                                               !3, ~51
         52      > JMPNZ                                                    ~52, ->5
   60    53    >   INIT_FCALL                                               'usort'
         54        SEND_REF                                                 !0
         55        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FYANU6%3A60%240'
   62    56        SEND_VAL                                                 ~53
         57        DO_ICALL                                                 
   64    58        INIT_FCALL                                               'array_map'
         59        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FYANU6%3A64%241'
   66    60        SEND_VAL                                                 ~55
         61        SEND_VAR                                                 !0
         62        DO_ICALL                                         $56     
         63      > RETURN                                                   $56
   67    64*     > RETURN                                                   null

End of function buildtop

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

End of function %00%7Bclosure%7D%2Fin%2FYANU6%3A60%240

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

End of function %00%7Bclosure%7D%2Fin%2FYANU6%3A64%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.24 ms | 1412 KiB | 27 Q