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], ]; $totalHotelsNumber = 2; $starCoef = 0.2; $ratingCoef = 2000; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } for ( $i=0; $i<count($hotels); $i++ ) { for ( $j=$i+1; $j<count($hotels); $j++ ) { echo 'Comparing '.$hotels[$i][0].' and '.$hotels[$j][0].'...'."\r\n"; $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); echo $price.' VS '.$hotels[$j][3]."\r\n"; if ( $price < $hotels[$j][3] ) { echo $hotels[$i][0].' wins!'."\r\n"; $hotels[$i][4]++; } else { echo $hotels[$j][0].' wins!'."\r\n"; $hotels[$j][4]++; } echo "\r\n".'----------'."\r\n"; } } usort($hotels, function($hotelA, $hotelB){ return $hotelB[4]-$hotelA[4]; }); echo "\r\n".'----------'."\r\n"; echo 'Top:'."\r\n\r\n"; for ( $i=0; $i<count($hotels); $i++ ) { echo $hotels[$i][0].': '.$hotels[$i][4]."\r\n"; } echo "\r\n".'----------'."\r\n"; echo 'Finalists:'."\r\n\r\n"; for ( $i=0; $i<=1; $i++ ) { echo $hotels[$i][0]."\r\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 6
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 15
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 108
Branch analysis from position: 108
2 jumps found. (Code = 44) Position 1 = 111, Position 2 = 99
Branch analysis from position: 111
1 jumps found. (Code = 42) Position 1 = 120
Branch analysis from position: 120
2 jumps found. (Code = 44) Position 1 = 122, Position 2 = 115
Branch analysis from position: 122
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 115
2 jumps found. (Code = 44) Position 1 = 122, Position 2 = 115
Branch analysis from position: 122
Branch analysis from position: 115
Branch analysis from position: 99
2 jumps found. (Code = 44) Position 1 = 111, Position 2 = 99
Branch analysis from position: 111
Branch analysis from position: 99
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
2 jumps found. (Code = 44) Position 1 = 86, Position 2 = 18
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 15
Branch analysis from position: 90
Branch analysis from position: 15
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 73
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 86, Position 2 = 18
Branch analysis from position: 86
Branch analysis from position: 18
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 86, Position 2 = 18
Branch analysis from position: 86
Branch analysis from position: 18
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 6
Branch analysis from position: 13
Branch analysis from position: 6
filename:       /in/IfksM
function name:  (null)
number of ops:  123
compiled vars:  !0 = $hotels, !1 = $totalHotelsNumber, !2 = $starCoef, !3 = $ratingCoef, !4 = $i, !5 = $j, !6 = $starDifference, !7 = $ratingToCompensate, !8 = $rating, !9 = $ratingDifference, !10 = $priceToCompensate, !11 = $price
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, 2
   13     2        ASSIGN                                                   !2, 0.2
   14     3        ASSIGN                                                   !3, 2000
   16     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->10
   17     6    >   FETCH_DIM_W                                      $17     !0, !4
          7        ASSIGN_DIM                                               $17, 4
          8        OP_DATA                                                  0
   16     9        PRE_INC                                                  !4
         10    >   COUNT                                            ~20     !0
         11        IS_SMALLER                                               !4, ~20
         12      > JMPNZ                                                    ~21, ->6
   20    13    >   ASSIGN                                                   !4, 0
         14      > JMP                                                      ->87
   21    15    >   ADD                                              ~23     !4, 1
         16        ASSIGN                                                   !5, ~23
         17      > JMP                                                      ->83
   22    18    >   FETCH_DIM_R                                      ~25     !0, !4
         19        FETCH_DIM_R                                      ~26     ~25, 0
         20        CONCAT                                           ~27     'Comparing+', ~26
         21        CONCAT                                           ~28     ~27, '+and+'
         22        FETCH_DIM_R                                      ~29     !0, !5
         23        FETCH_DIM_R                                      ~30     ~29, 0
         24        CONCAT                                           ~31     ~28, ~30
         25        CONCAT                                           ~32     ~31, '...'
         26        CONCAT                                           ~33     ~32, '%0D%0A'
         27        ECHO                                                     ~33
   24    28        FETCH_DIM_R                                      ~34     !0, !4
         29        FETCH_DIM_R                                      ~35     ~34, 1
         30        FETCH_DIM_R                                      ~36     !0, !5
         31        FETCH_DIM_R                                      ~37     ~36, 1
         32        SUB                                              ~38     ~35, ~37
         33        ASSIGN                                                   !6, ~38
   25    34        MUL                                              ~40     !6, !2
         35        ASSIGN                                                   !7, ~40
   26    36        FETCH_DIM_R                                      ~42     !0, !4
         37        FETCH_DIM_R                                      ~43     ~42, 2
         38        ADD                                              ~44     ~43, !7
         39        ASSIGN                                                   !8, ~44
   28    40        FETCH_DIM_R                                      ~46     !0, !5
         41        FETCH_DIM_R                                      ~47     ~46, 2
         42        SUB                                              ~48     !8, ~47
         43        MUL                                              ~49     ~48, 10
         44        ASSIGN                                                   !9, ~49
   29    45        MUL                                              ~51     !9, !3
         46        ASSIGN                                                   !10, ~51
   30    47        INIT_FCALL                                               'round'
         48        FETCH_DIM_R                                      ~53     !0, !4
         49        FETCH_DIM_R                                      ~54     ~53, 3
         50        SUB                                              ~55     ~54, !10
         51        SEND_VAL                                                 ~55
         52        DO_ICALL                                         $56     
         53        ASSIGN                                                   !11, $56
   32    54        CONCAT                                           ~58     !11, '+VS+'
         55        FETCH_DIM_R                                      ~59     !0, !5
         56        FETCH_DIM_R                                      ~60     ~59, 3
         57        CONCAT                                           ~61     ~58, ~60
         58        CONCAT                                           ~62     ~61, '%0D%0A'
         59        ECHO                                                     ~62
   33    60        FETCH_DIM_R                                      ~63     !0, !5
         61        FETCH_DIM_R                                      ~64     ~63, 3
         62        IS_SMALLER                                               !11, ~64
         63      > JMPZ                                                     ~65, ->73
   34    64    >   FETCH_DIM_R                                      ~66     !0, !4
         65        FETCH_DIM_R                                      ~67     ~66, 0
         66        CONCAT                                           ~68     ~67, '+wins%21'
         67        CONCAT                                           ~69     ~68, '%0D%0A'
         68        ECHO                                                     ~69
   35    69        FETCH_DIM_RW                                     $70     !0, !4
         70        FETCH_DIM_RW                                     $71     $70, 4
         71        PRE_INC                                                  $71
         72      > JMP                                                      ->81
   37    73    >   FETCH_DIM_R                                      ~73     !0, !5
         74        FETCH_DIM_R                                      ~74     ~73, 0
         75        CONCAT                                           ~75     ~74, '+wins%21'
         76        CONCAT                                           ~76     ~75, '%0D%0A'
         77        ECHO                                                     ~76
   38    78        FETCH_DIM_RW                                     $77     !0, !5
         79        FETCH_DIM_RW                                     $78     $77, 4
         80        PRE_INC                                                  $78
   41    81    >   ECHO                                                     '%0D%0A----------%0D%0A'
   21    82        PRE_INC                                                  !5
         83    >   COUNT                                            ~81     !0
         84        IS_SMALLER                                               !5, ~81
         85      > JMPNZ                                                    ~82, ->18
   20    86    >   PRE_INC                                                  !4
         87    >   COUNT                                            ~84     !0
         88        IS_SMALLER                                               !4, ~84
         89      > JMPNZ                                                    ~85, ->15
   45    90    >   INIT_FCALL                                               'usort'
         91        SEND_REF                                                 !0
         92        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIfksM%3A45%240'
   47    93        SEND_VAL                                                 ~86
         94        DO_ICALL                                                 
   49    95        ECHO                                                     '%0D%0A----------%0D%0A'
   51    96        ECHO                                                     'Top%3A%0D%0A%0D%0A'
   52    97        ASSIGN                                                   !4, 0
         98      > JMP                                                      ->108
   53    99    >   FETCH_DIM_R                                      ~89     !0, !4
        100        FETCH_DIM_R                                      ~90     ~89, 0
        101        CONCAT                                           ~91     ~90, '%3A+'
        102        FETCH_DIM_R                                      ~92     !0, !4
        103        FETCH_DIM_R                                      ~93     ~92, 4
        104        CONCAT                                           ~94     ~91, ~93
        105        CONCAT                                           ~95     ~94, '%0D%0A'
        106        ECHO                                                     ~95
   52   107        PRE_INC                                                  !4
        108    >   COUNT                                            ~97     !0
        109        IS_SMALLER                                               !4, ~97
        110      > JMPNZ                                                    ~98, ->99
   56   111    >   ECHO                                                     '%0D%0A----------%0D%0A'
   57   112        ECHO                                                     'Finalists%3A%0D%0A%0D%0A'
   59   113        ASSIGN                                                   !4, 0
        114      > JMP                                                      ->120
   60   115    >   FETCH_DIM_R                                      ~100    !0, !4
        116        FETCH_DIM_R                                      ~101    ~100, 0
        117        CONCAT                                           ~102    ~101, '%0D%0A'
        118        ECHO                                                     ~102
   59   119        PRE_INC                                                  !4
        120    >   IS_SMALLER_OR_EQUAL                                      !4, 1
        121      > JMPNZ                                                    ~104, ->115
   61   122    > > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FIfksM%3A45%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.78 ms | 1400 KiB | 17 Q