3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Bliss', 3, 8.0, 31046], ['Dorset', 4, 8.1, 34839], ['Innotel', 4, 8.2, 36266], ['Rendezvouz', 4, 8.3, 37696], ['The', 4, 8.4, 41515], ['Karlton', 5, 8.2, 42799], ['Karlton City', 4, 8.5, 43431], ['Swiss', 5, 8.3, 43431], ['New', 4, 8.5, 45291], ['Park', 4, 8.6, 46208], ['Swiss The', 5, 8.4, 47985], ['Fair', 5, 8.7, 52650], ]; $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"; }
Output for 5.4.0 - 7.1.0
Comparing Bliss and Dorset... 37046 VS 34839 Dorset wins! ---------- Comparing Bliss and Innotel... 39046 VS 36266 Innotel wins! ---------- Comparing Bliss and Rendezvouz... 41046 VS 37696 Rendezvouz wins! ---------- Comparing Bliss and The... 43046 VS 41515 The wins! ---------- Comparing Bliss and Karlton... 43046 VS 42799 Karlton wins! ---------- Comparing Bliss and Karlton City... 45046 VS 43431 Karlton City wins! ---------- Comparing Bliss and Swiss... 45046 VS 43431 Swiss wins! ---------- Comparing Bliss and New... 45046 VS 45291 Bliss wins! ---------- Comparing Bliss and Park... 47046 VS 46208 Park wins! ---------- Comparing Bliss and Swiss The... 47046 VS 47985 Bliss wins! ---------- Comparing Bliss and Fair... 53046 VS 52650 Fair wins! ---------- Comparing Dorset and Innotel... 36839 VS 36266 Innotel wins! ---------- Comparing Dorset and Rendezvouz... 38839 VS 37696 Rendezvouz wins! ---------- Comparing Dorset and The... 40839 VS 41515 Dorset wins! ---------- Comparing Dorset and Karlton... 40839 VS 42799 Dorset wins! ---------- Comparing Dorset and Karlton City... 42839 VS 43431 Dorset wins! ---------- Comparing Dorset and Swiss... 42839 VS 43431 Dorset wins! ---------- Comparing Dorset and New... 42839 VS 45291 Dorset wins! ---------- Comparing Dorset and Park... 44839 VS 46208 Dorset wins! ---------- Comparing Dorset and Swiss The... 44839 VS 47985 Dorset wins! ---------- Comparing Dorset and Fair... 50839 VS 52650 Dorset wins! ---------- Comparing Innotel and Rendezvouz... 38266 VS 37696 Rendezvouz wins! ---------- Comparing Innotel and The... 40266 VS 41515 Innotel wins! ---------- Comparing Innotel and Karlton... 40266 VS 42799 Innotel wins! ---------- Comparing Innotel and Karlton City... 42266 VS 43431 Innotel wins! ---------- Comparing Innotel and Swiss... 42266 VS 43431 Innotel wins! ---------- Comparing Innotel and New... 42266 VS 45291 Innotel wins! ---------- Comparing Innotel and Park... 44266 VS 46208 Innotel wins! ---------- Comparing Innotel and Swiss The... 44266 VS 47985 Innotel wins! ---------- Comparing Innotel and Fair... 50266 VS 52650 Innotel wins! ---------- Comparing Rendezvouz and The... 39696 VS 41515 Rendezvouz wins! ---------- Comparing Rendezvouz and Karlton... 39696 VS 42799 Rendezvouz wins! ---------- Comparing Rendezvouz and Karlton City... 41696 VS 43431 Rendezvouz wins! ---------- Comparing Rendezvouz and Swiss... 41696 VS 43431 Rendezvouz wins! ---------- Comparing Rendezvouz and New... 41696 VS 45291 Rendezvouz wins! ---------- Comparing Rendezvouz and Park... 43696 VS 46208 Rendezvouz wins! ---------- Comparing Rendezvouz and Swiss The... 43696 VS 47985 Rendezvouz wins! ---------- Comparing Rendezvouz and Fair... 49696 VS 52650 Rendezvouz wins! ---------- Comparing The and Karlton... 41515 VS 42799 The wins! ---------- Comparing The and Karlton City... 43515 VS 43431 Karlton City wins! ---------- Comparing The and Swiss... 43515 VS 43431 Swiss wins! ---------- Comparing The and New... 43515 VS 45291 The wins! ---------- Comparing The and Park... 45515 VS 46208 The wins! ---------- Comparing The and Swiss The... 45515 VS 47985 The wins! ---------- Comparing The and Fair... 51515 VS 52650 The wins! ---------- Comparing Karlton and Karlton City... 44799 VS 43431 Karlton City wins! ---------- Comparing Karlton and Swiss... 44799 VS 43431 Swiss wins! ---------- Comparing Karlton and New... 44799 VS 45291 Karlton wins! ---------- Comparing Karlton and Park... 46799 VS 46208 Park wins! ---------- Comparing Karlton and Swiss The... 46799 VS 47985 Karlton wins! ---------- Comparing Karlton and Fair... 52799 VS 52650 Fair wins! ---------- Comparing Karlton City and Swiss... 43431 VS 43431 Swiss wins! ---------- Comparing Karlton City and New... 43431 VS 45291 Karlton City wins! ---------- Comparing Karlton City and Park... 45431 VS 46208 Karlton City wins! ---------- Comparing Karlton City and Swiss The... 45431 VS 47985 Karlton City wins! ---------- Comparing Karlton City and Fair... 51431 VS 52650 Karlton City wins! ---------- Comparing Swiss and New... 43431 VS 45291 Swiss wins! ---------- Comparing Swiss and Park... 45431 VS 46208 Swiss wins! ---------- Comparing Swiss and Swiss The... 45431 VS 47985 Swiss wins! ---------- Comparing Swiss and Fair... 51431 VS 52650 Swiss wins! ---------- Comparing New and Park... 47291 VS 46208 Park wins! ---------- Comparing New and Swiss The... 47291 VS 47985 New wins! ---------- Comparing New and Fair... 53291 VS 52650 Fair wins! ---------- Comparing Park and Swiss The... 46208 VS 47985 Park wins! ---------- Comparing Park and Fair... 52208 VS 52650 Park wins! ---------- Comparing Swiss The and Fair... 53985 VS 52650 Fair wins! ---------- ---------- Top: Rendezvouz: 11 Innotel: 10 Dorset: 9 Swiss: 8 Karlton City: 7 The: 6 Park: 5 Fair: 4 Karlton: 3 Bliss: 2 New: 1 Swiss The: 0 ---------- Finalists: Rendezvouz Innotel
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/O5FY8 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/O5FY8 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/O5FY8 on line 3
Process exited with code 255.