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

End of function buildtop

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

End of function %00%7Bclosure%7D%2Fin%2F7E68Q%3A56%240

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

End of function %00%7Bclosure%7D%2Fin%2F7E68Q%3A60%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.43 ms | 1400 KiB | 23 Q