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; } //$starCoefOptions = range(0.02, 5, 0.02); //$ratingCoefOptions = range(50, 10000, 50); $starCoefOptions = array(0.1, 0.2); $ratingCoefOptions = array(1000, 2000); foreach ( $starCoefOptions as $starCoef ) { foreach ( $ratingCoefOptions as $ratingCoef ) { $topGenerated = buildTop($hotels, $starCoef, $ratingCoef); $topGenerated = array_slice($topGenerated, 0, count($top)); var_dump($topGenerated); 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 = 14, Position 2 = 45
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 45
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 43
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 43
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 42
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 42
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 43
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
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/YrB3m
function name:  (null)
number of ops:  47
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
   24    11    >   ASSIGN                                                   !3, <array>
   25    12        ASSIGN                                                   !4, <array>
   27    13      > FE_RESET_R                                       $18     !3, ->45
         14    > > FE_FETCH_R                                               $18, !5, ->45
   28    15    > > FE_RESET_R                                       $19     !4, ->43
         16    > > FE_FETCH_R                                               $19, !6, ->43
   29    17    >   INIT_FCALL_BY_NAME                                       'buildTop'
         18        SEND_VAR_EX                                              !0
         19        SEND_VAR_EX                                              !5
         20        SEND_VAR_EX                                              !6
         21        DO_FCALL                                      0  $20     
         22        ASSIGN                                                   !7, $20
   30    23        INIT_FCALL                                               'array_slice'
         24        SEND_VAR                                                 !7
         25        SEND_VAL                                                 0
         26        COUNT                                            ~22     !1
         27        SEND_VAL                                                 ~22
         28        DO_ICALL                                         $23     
         29        ASSIGN                                                   !7, $23
   31    30        INIT_FCALL                                               'var_dump'
         31        SEND_VAR                                                 !7
         32        DO_ICALL                                                 
   32    33        IS_IDENTICAL                                             !7, !1
         34      > JMPZ                                                     ~26, ->42
   33    35    >   CONCAT                                           ~27     '%24starCoef+%3D+', !5
         36        CONCAT                                           ~28     ~27, '%0D%0A'
         37        ECHO                                                     ~28
   34    38        CONCAT                                           ~29     '%24ratingCoef+%3D+', !6
         39        CONCAT                                           ~30     ~29, '%0D%0A'
         40        ECHO                                                     ~30
   35    41        ECHO                                                     '%0D%0A'
   28    42    > > JMP                                                      ->16
         43    >   FE_FREE                                                  $19
   27    44      > JMP                                                      ->14
         45    >   FE_FREE                                                  $18
   67    46      > 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/YrB3m
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%2FYrB3m%3A60%240'
   62    56        SEND_VAL                                                 ~53
         57        DO_ICALL                                                 
   64    58        INIT_FCALL                                               'array_map'
         59        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FYrB3m%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%2FYrB3m%3A60%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YrB3m
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%2FYrB3m%3A60%240

Function %00%7Bclosure%7D%2Fin%2FYrB3m%3A64%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YrB3m
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%2FYrB3m%3A64%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.98 ms | 1408 KiB | 23 Q