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; echo $priceToCompensate."\r\n"; $price = $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 = 86
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 89, Position 2 = 15
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 107
Branch analysis from position: 107
2 jumps found. (Code = 44) Position 1 = 110, Position 2 = 98
Branch analysis from position: 110
1 jumps found. (Code = 42) Position 1 = 119
Branch analysis from position: 119
2 jumps found. (Code = 44) Position 1 = 121, Position 2 = 114
Branch analysis from position: 121
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 114
2 jumps found. (Code = 44) Position 1 = 121, Position 2 = 114
Branch analysis from position: 121
Branch analysis from position: 114
Branch analysis from position: 98
2 jumps found. (Code = 44) Position 1 = 110, Position 2 = 98
Branch analysis from position: 110
Branch analysis from position: 98
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 18
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 89, Position 2 = 15
Branch analysis from position: 89
Branch analysis from position: 15
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 72
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 18
Branch analysis from position: 85
Branch analysis from position: 18
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 18
Branch analysis from position: 85
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/pu3rZ
function name:  (null)
number of ops:  122
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                                                      ->86
   21    15    >   ADD                                              ~23     !4, 1
         16        ASSIGN                                                   !5, ~23
         17      > JMP                                                      ->82
   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        CONCAT                                           ~53     !10, '%0D%0A'
         48        ECHO                                                     ~53
   31    49        FETCH_DIM_R                                      ~54     !0, !4
         50        FETCH_DIM_R                                      ~55     ~54, 3
         51        SUB                                              ~56     ~55, !10
         52        ASSIGN                                                   !11, ~56
   33    53        CONCAT                                           ~58     !11, '+VS+'
         54        FETCH_DIM_R                                      ~59     !0, !5
         55        FETCH_DIM_R                                      ~60     ~59, 3
         56        CONCAT                                           ~61     ~58, ~60
         57        CONCAT                                           ~62     ~61, '%0D%0A'
         58        ECHO                                                     ~62
   34    59        FETCH_DIM_R                                      ~63     !0, !5
         60        FETCH_DIM_R                                      ~64     ~63, 3
         61        IS_SMALLER                                               ~64, !11
         62      > JMPZ                                                     ~65, ->72
   35    63    >   FETCH_DIM_R                                      ~66     !0, !4
         64        FETCH_DIM_R                                      ~67     ~66, 0
         65        CONCAT                                           ~68     ~67, '+wins%21'
         66        CONCAT                                           ~69     ~68, '%0D%0A'
         67        ECHO                                                     ~69
   36    68        FETCH_DIM_RW                                     $70     !0, !4
         69        FETCH_DIM_RW                                     $71     $70, 4
         70        PRE_INC                                                  $71
         71      > JMP                                                      ->80
   38    72    >   FETCH_DIM_R                                      ~73     !0, !5
         73        FETCH_DIM_R                                      ~74     ~73, 0
         74        CONCAT                                           ~75     ~74, '+wins%21'
         75        CONCAT                                           ~76     ~75, '%0D%0A'
         76        ECHO                                                     ~76
   39    77        FETCH_DIM_RW                                     $77     !0, !5
         78        FETCH_DIM_RW                                     $78     $77, 4
         79        PRE_INC                                                  $78
   42    80    >   ECHO                                                     '%0D%0A----------%0D%0A'
   21    81        PRE_INC                                                  !5
         82    >   COUNT                                            ~81     !0
         83        IS_SMALLER                                               !5, ~81
         84      > JMPNZ                                                    ~82, ->18
   20    85    >   PRE_INC                                                  !4
         86    >   COUNT                                            ~84     !0
         87        IS_SMALLER                                               !4, ~84
         88      > JMPNZ                                                    ~85, ->15
   46    89    >   INIT_FCALL                                               'usort'
         90        SEND_REF                                                 !0
         91        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fpu3rZ%3A46%240'
   48    92        SEND_VAL                                                 ~86
         93        DO_ICALL                                                 
   50    94        ECHO                                                     '%0D%0A----------%0D%0A'
   52    95        ECHO                                                     'Top%3A%0D%0A%0D%0A'
   53    96        ASSIGN                                                   !4, 0
         97      > JMP                                                      ->107
   54    98    >   FETCH_DIM_R                                      ~89     !0, !4
         99        FETCH_DIM_R                                      ~90     ~89, 0
        100        CONCAT                                           ~91     ~90, '%3A+'
        101        FETCH_DIM_R                                      ~92     !0, !4
        102        FETCH_DIM_R                                      ~93     ~92, 4
        103        CONCAT                                           ~94     ~91, ~93
        104        CONCAT                                           ~95     ~94, '%0D%0A'
        105        ECHO                                                     ~95
   53   106        PRE_INC                                                  !4
        107    >   COUNT                                            ~97     !0
        108        IS_SMALLER                                               !4, ~97
        109      > JMPNZ                                                    ~98, ->98
   57   110    >   ECHO                                                     '%0D%0A----------%0D%0A'
   58   111        ECHO                                                     'Finalists%3A%0D%0A%0D%0A'
   60   112        ASSIGN                                                   !4, 0
        113      > JMP                                                      ->119
   61   114    >   FETCH_DIM_R                                      ~100    !0, !4
        115        FETCH_DIM_R                                      ~101    ~100, 0
        116        CONCAT                                           ~102    ~101, '%0D%0A'
        117        ECHO                                                     ~102
   60   118        PRE_INC                                                  !4
        119    >   IS_SMALLER_OR_EQUAL                                      !4, 1
        120      > JMPNZ                                                    ~104, ->114
   62   121    > > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2Fpu3rZ%3A46%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.03 ms | 1408 KiB | 15 Q