3v4l.org

run code in 300+ PHP versions simultaneously
<?php $hotels = [ ['Villa', 4, 8.5, 40398], ['Uvala', 4, 8.3, 52126], ['Valmar', 4, 8.6, 53104], ['Grand Hotel', 4, 8.1, 59340], ['Neptun', 4, 8.8, 61444], ['Valamar', 4, 8.7, 62365], ['Ariston', 5, 8.8, 68937], ['Rixos', 5, 8.5, 70370], ['Butique', 5, 9.2, 79818], ]; $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 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Comparing Villa and Uvala... 36398 VS 52126 Villa wins! ---------- Comparing Villa and Valmar... 42398 VS 53104 Villa wins! ---------- Comparing Villa and Grand Hotel... 32398 VS 59340 Villa wins! ---------- Comparing Villa and Neptun... 46398 VS 61444 Villa wins! ---------- Comparing Villa and Valamar... 44398 VS 62365 Villa wins! ---------- Comparing Villa and Ariston... 50398 VS 68937 Villa wins! ---------- Comparing Villa and Rixos... 44398 VS 70370 Villa wins! ---------- Comparing Villa and Butique... 58398 VS 79818 Villa wins! ---------- Comparing Uvala and Valmar... 58126 VS 53104 Valmar wins! ---------- Comparing Uvala and Grand Hotel... 48126 VS 59340 Uvala wins! ---------- Comparing Uvala and Neptun... 62126 VS 61444 Neptun wins! ---------- Comparing Uvala and Valamar... 60126 VS 62365 Uvala wins! ---------- Comparing Uvala and Ariston... 66126 VS 68937 Uvala wins! ---------- Comparing Uvala and Rixos... 60126 VS 70370 Uvala wins! ---------- Comparing Uvala and Butique... 74126 VS 79818 Uvala wins! ---------- Comparing Valmar and Grand Hotel... 43104 VS 59340 Valmar wins! ---------- Comparing Valmar and Neptun... 57104 VS 61444 Valmar wins! ---------- Comparing Valmar and Valamar... 55104 VS 62365 Valmar wins! ---------- Comparing Valmar and Ariston... 61104 VS 68937 Valmar wins! ---------- Comparing Valmar and Rixos... 55104 VS 70370 Valmar wins! ---------- Comparing Valmar and Butique... 69104 VS 79818 Valmar wins! ---------- Comparing Grand Hotel and Neptun... 73340 VS 61444 Neptun wins! ---------- Comparing Grand Hotel and Valamar... 71340 VS 62365 Valamar wins! ---------- Comparing Grand Hotel and Ariston... 77340 VS 68937 Ariston wins! ---------- Comparing Grand Hotel and Rixos... 71340 VS 70370 Rixos wins! ---------- Comparing Grand Hotel and Butique... 85340 VS 79818 Butique wins! ---------- Comparing Neptun and Valamar... 59444 VS 62365 Neptun wins! ---------- Comparing Neptun and Ariston... 65444 VS 68937 Neptun wins! ---------- Comparing Neptun and Rixos... 59444 VS 70370 Neptun wins! ---------- Comparing Neptun and Butique... 73444 VS 79818 Neptun wins! ---------- Comparing Valamar and Ariston... 68365 VS 68937 Valamar wins! ---------- Comparing Valamar and Rixos... 62365 VS 70370 Valamar wins! ---------- Comparing Valamar and Butique... 76365 VS 79818 Valamar wins! ---------- Comparing Ariston and Rixos... 62937 VS 70370 Ariston wins! ---------- Comparing Ariston and Butique... 76937 VS 79818 Ariston wins! ---------- Comparing Rixos and Butique... 84370 VS 79818 Butique wins! ---------- ---------- Top: Villa: 8 Valmar: 7 Neptun: 6 Uvala: 5 Valamar: 4 Ariston: 3 Butique: 2 Rixos: 1 Grand Hotel: 0 ---------- Finalists: Villa Valmar
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/k9sII on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/k9sII on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/k9sII on line 3
Process exited with code 255.

preferences:
239.86 ms | 401 KiB | 313 Q