3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Vik', 4, 8.3, 31393], ['Catalonia', 5, 8.4, 33240], ['Ifa', 4, 8.3, 39363], ['Babaro', 5, 8.4, 44059], ['Catalonia Royal', 5, 8.7, 50258], ['Grand Pala', 5, 8.8, 61231], ['Majestic', 5, 8.9, 64693], ['Bilif', 5, 8.0, 68121], ['Nau', 5, 8.5, 72116], ['Paradis', 5, 8.4, 77510], ['Majestic El', 5, 8.9, 80791] ]; $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 Vik and Catalonia... 37393 VS 33240 Catalonia wins! ---------- Comparing Vik and Ifa... 31393 VS 39363 Vik wins! ---------- Comparing Vik and Babaro... 37393 VS 44059 Vik wins! ---------- Comparing Vik and Catalonia Royal... 43393 VS 50258 Vik wins! ---------- Comparing Vik and Grand Pala... 45393 VS 61231 Vik wins! ---------- Comparing Vik and Majestic... 47393 VS 64693 Vik wins! ---------- Comparing Vik and Bilif... 29393 VS 68121 Vik wins! ---------- Comparing Vik and Nau... 39393 VS 72116 Vik wins! ---------- Comparing Vik and Paradis... 37393 VS 77510 Vik wins! ---------- Comparing Vik and Majestic El... 47393 VS 80791 Vik wins! ---------- Comparing Catalonia and Ifa... 27240 VS 39363 Catalonia wins! ---------- Comparing Catalonia and Babaro... 33240 VS 44059 Catalonia wins! ---------- Comparing Catalonia and Catalonia Royal... 39240 VS 50258 Catalonia wins! ---------- Comparing Catalonia and Grand Pala... 41240 VS 61231 Catalonia wins! ---------- Comparing Catalonia and Majestic... 43240 VS 64693 Catalonia wins! ---------- Comparing Catalonia and Bilif... 25240 VS 68121 Catalonia wins! ---------- Comparing Catalonia and Nau... 35240 VS 72116 Catalonia wins! ---------- Comparing Catalonia and Paradis... 33240 VS 77510 Catalonia wins! ---------- Comparing Catalonia and Majestic El... 43240 VS 80791 Catalonia wins! ---------- Comparing Ifa and Babaro... 45363 VS 44059 Babaro wins! ---------- Comparing Ifa and Catalonia Royal... 51363 VS 50258 Catalonia Royal wins! ---------- Comparing Ifa and Grand Pala... 53363 VS 61231 Ifa wins! ---------- Comparing Ifa and Majestic... 55363 VS 64693 Ifa wins! ---------- Comparing Ifa and Bilif... 37363 VS 68121 Ifa wins! ---------- Comparing Ifa and Nau... 47363 VS 72116 Ifa wins! ---------- Comparing Ifa and Paradis... 45363 VS 77510 Ifa wins! ---------- Comparing Ifa and Majestic El... 55363 VS 80791 Ifa wins! ---------- Comparing Babaro and Catalonia Royal... 50059 VS 50258 Babaro wins! ---------- Comparing Babaro and Grand Pala... 52059 VS 61231 Babaro wins! ---------- Comparing Babaro and Majestic... 54059 VS 64693 Babaro wins! ---------- Comparing Babaro and Bilif... 36059 VS 68121 Babaro wins! ---------- Comparing Babaro and Nau... 46059 VS 72116 Babaro wins! ---------- Comparing Babaro and Paradis... 44059 VS 77510 Babaro wins! ---------- Comparing Babaro and Majestic El... 54059 VS 80791 Babaro wins! ---------- Comparing Catalonia Royal and Grand Pala... 52258 VS 61231 Catalonia Royal wins! ---------- Comparing Catalonia Royal and Majestic... 54258 VS 64693 Catalonia Royal wins! ---------- Comparing Catalonia Royal and Bilif... 36258 VS 68121 Catalonia Royal wins! ---------- Comparing Catalonia Royal and Nau... 46258 VS 72116 Catalonia Royal wins! ---------- Comparing Catalonia Royal and Paradis... 44258 VS 77510 Catalonia Royal wins! ---------- Comparing Catalonia Royal and Majestic El... 54258 VS 80791 Catalonia Royal wins! ---------- Comparing Grand Pala and Majestic... 63231 VS 64693 Grand Pala wins! ---------- Comparing Grand Pala and Bilif... 45231 VS 68121 Grand Pala wins! ---------- Comparing Grand Pala and Nau... 55231 VS 72116 Grand Pala wins! ---------- Comparing Grand Pala and Paradis... 53231 VS 77510 Grand Pala wins! ---------- Comparing Grand Pala and Majestic El... 63231 VS 80791 Grand Pala wins! ---------- Comparing Majestic and Bilif... 46693 VS 68121 Majestic wins! ---------- Comparing Majestic and Nau... 56693 VS 72116 Majestic wins! ---------- Comparing Majestic and Paradis... 54693 VS 77510 Majestic wins! ---------- Comparing Majestic and Majestic El... 64693 VS 80791 Majestic wins! ---------- Comparing Bilif and Nau... 78121 VS 72116 Nau wins! ---------- Comparing Bilif and Paradis... 76121 VS 77510 Bilif wins! ---------- Comparing Bilif and Majestic El... 86121 VS 80791 Majestic El wins! ---------- Comparing Nau and Paradis... 70116 VS 77510 Nau wins! ---------- Comparing Nau and Majestic El... 80116 VS 80791 Nau wins! ---------- Comparing Paradis and Majestic El... 87510 VS 80791 Majestic El wins! ---------- ---------- Top: Catalonia: 10 Vik: 9 Babaro: 8 Catalonia Royal: 7 Ifa: 6 Grand Pala: 5 Majestic: 4 Nau: 3 Majestic El: 2 Bilif: 1 Paradis: 0 ---------- Finalists: Catalonia Vik
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/4BhAk 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/4BhAk on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/4BhAk on line 3
Process exited with code 255.