3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Mar', 4, 8.0, 38770], ['Vilamar', 4, 8.0, 45400], ['Enidor', 4, 8.0, 48060], ['Vinsdor', 3, 8.2, 50210], ['Palace', 4, 8.1, 52343], ['Mirasol', 4, 8.1, 52480], ['Blisa', 5, 8.3, 54280], ]; $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.10.0 - 3.12.0, 7.0.0 - 7.1.0
Comparing Mar and Vilamar... 38770 VS 45400 Mar wins! ---------- Comparing Mar and Enidor... 38770 VS 48060 Mar wins! ---------- Comparing Mar and Vinsdor... 38770 VS 50210 Mar wins! ---------- Comparing Mar and Palace... 40770 VS 52343 Mar wins! ---------- Comparing Mar and Mirasol... 40770 VS 52480 Mar wins! ---------- Comparing Mar and Blisa... 48770 VS 54280 Mar wins! ---------- Comparing Vilamar and Enidor... 45400 VS 48060 Vilamar wins! ---------- Comparing Vilamar and Vinsdor... 45400 VS 50210 Vilamar wins! ---------- Comparing Vilamar and Palace... 47400 VS 52343 Vilamar wins! ---------- Comparing Vilamar and Mirasol... 47400 VS 52480 Vilamar wins! ---------- Comparing Vilamar and Blisa... 55400 VS 54280 Blisa wins! ---------- Comparing Enidor and Vinsdor... 48060 VS 50210 Enidor wins! ---------- Comparing Enidor and Palace... 50060 VS 52343 Enidor wins! ---------- Comparing Enidor and Mirasol... 50060 VS 52480 Enidor wins! ---------- Comparing Enidor and Blisa... 58060 VS 54280 Blisa wins! ---------- Comparing Vinsdor and Palace... 52210 VS 52343 Vinsdor wins! ---------- Comparing Vinsdor and Mirasol... 52210 VS 52480 Vinsdor wins! ---------- Comparing Vinsdor and Blisa... 60210 VS 54280 Blisa wins! ---------- Comparing Palace and Mirasol... 52343 VS 52480 Palace wins! ---------- Comparing Palace and Blisa... 60343 VS 54280 Blisa wins! ---------- Comparing Mirasol and Blisa... 60480 VS 54280 Blisa wins! ---------- ---------- Top: Mar: 6 Blisa: 5 Vilamar: 4 Enidor: 3 Vinsdor: 2 Palace: 1 Mirasol: 0 ---------- Finalists: Mar Blisa
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/72pZ8 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/72pZ8 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/72pZ8 on line 3
Process exited with code 255.