3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Premier', 3, 8.1, 12472], ['Premier Park', 3, 8.0, 14525], ['Premier Airoport', 3, 8.4, 17390], ['Porpoints', 4, 8.0, 19195], ['arabiain', 4, 8.1, 20749], ['La meridian', 5, 8.4, 21147], ['Sheraton', 5, 8.8, 22351], ['Savoy', 0, 8.2, 22438], ['Hiyat', 4, 8.5, 23240], ['Hilton', 5, 8.2, 24000], ]; $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.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Comparing Premier and Premier Park... 10472 VS 14525 Premier wins! ---------- Comparing Premier and Premier Airoport... 18472 VS 17390 Premier Airoport wins! ---------- Comparing Premier and Porpoints... 14472 VS 19195 Premier wins! ---------- Comparing Premier and arabiain... 16472 VS 20749 Premier wins! ---------- Comparing Premier and La meridian... 26472 VS 21147 La meridian wins! ---------- Comparing Premier and Sheraton... 34472 VS 22351 Sheraton wins! ---------- Comparing Premier and Savoy... 2472 VS 22438 Premier wins! ---------- Comparing Premier and Hiyat... 24472 VS 23240 Hiyat wins! ---------- Comparing Premier and Hilton... 22472 VS 24000 Premier wins! ---------- Comparing Premier Park and Premier Airoport... 22525 VS 17390 Premier Airoport wins! ---------- Comparing Premier Park and Porpoints... 18525 VS 19195 Premier Park wins! ---------- Comparing Premier Park and arabiain... 20525 VS 20749 Premier Park wins! ---------- Comparing Premier Park and La meridian... 30525 VS 21147 La meridian wins! ---------- Comparing Premier Park and Sheraton... 38525 VS 22351 Sheraton wins! ---------- Comparing Premier Park and Savoy... 6525 VS 22438 Premier Park wins! ---------- Comparing Premier Park and Hiyat... 28525 VS 23240 Hiyat wins! ---------- Comparing Premier Park and Hilton... 26525 VS 24000 Hilton wins! ---------- Comparing Premier Airoport and Porpoints... 13390 VS 19195 Premier Airoport wins! ---------- Comparing Premier Airoport and arabiain... 15390 VS 20749 Premier Airoport wins! ---------- Comparing Premier Airoport and La meridian... 25390 VS 21147 La meridian wins! ---------- Comparing Premier Airoport and Sheraton... 33390 VS 22351 Sheraton wins! ---------- Comparing Premier Airoport and Savoy... 1390 VS 22438 Premier Airoport wins! ---------- Comparing Premier Airoport and Hiyat... 23390 VS 23240 Hiyat wins! ---------- Comparing Premier Airoport and Hilton... 21390 VS 24000 Premier Airoport wins! ---------- Comparing Porpoints and arabiain... 21195 VS 20749 arabiain wins! ---------- Comparing Porpoints and La meridian... 31195 VS 21147 La meridian wins! ---------- Comparing Porpoints and Sheraton... 39195 VS 22351 Sheraton wins! ---------- Comparing Porpoints and Savoy... 7195 VS 22438 Porpoints wins! ---------- Comparing Porpoints and Hiyat... 29195 VS 23240 Hiyat wins! ---------- Comparing Porpoints and Hilton... 27195 VS 24000 Hilton wins! ---------- Comparing arabiain and La meridian... 30749 VS 21147 La meridian wins! ---------- Comparing arabiain and Sheraton... 38749 VS 22351 Sheraton wins! ---------- Comparing arabiain and Savoy... 6749 VS 22438 arabiain wins! ---------- Comparing arabiain and Hiyat... 28749 VS 23240 Hiyat wins! ---------- Comparing arabiain and Hilton... 26749 VS 24000 Hilton wins! ---------- Comparing La meridian and Sheraton... 29147 VS 22351 Sheraton wins! ---------- Comparing La meridian and Savoy... -2853 VS 22438 La meridian wins! ---------- Comparing La meridian and Hiyat... 19147 VS 23240 La meridian wins! ---------- Comparing La meridian and Hilton... 17147 VS 24000 La meridian wins! ---------- Comparing Sheraton and Savoy... -9649 VS 22438 Sheraton wins! ---------- Comparing Sheraton and Hiyat... 12351 VS 23240 Sheraton wins! ---------- Comparing Sheraton and Hilton... 10351 VS 24000 Sheraton wins! ---------- Comparing Savoy and Hiyat... 44438 VS 23240 Hiyat wins! ---------- Comparing Savoy and Hilton... 42438 VS 24000 Hilton wins! ---------- Comparing Hiyat and Hilton... 21240 VS 24000 Hiyat wins! ---------- ---------- Top: Sheraton: 9 La meridian: 8 Hiyat: 7 Premier Airoport: 6 Premier: 5 Hilton: 4 Premier Park: 3 arabiain: 2 Porpoints: 1 Savoy: 0 ---------- Finalists: Sheraton La meridian
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/7SIEU 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/7SIEU on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/7SIEU on line 3
Process exited with code 255.