3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Mercury', 4, 8.7, 15212], ['Novotel', 4, 8.5, 18147], ['Sheraton', 5, 8.7, 19342], ['Redison', 5, 8.7, 22841], ['Polonia', 4, 9.1, 23109], ['Merc Varsh', 4, 8.7, 24431], ['Sofitel', 5, 9.0, 25719], ['Varah Mar', 5, 8.7, 26268], ['Hotel', 5, 8.9, 28004], ['Hotel dristol', 5, 9.2, 29843], ]; $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 Mercury and Novotel... 11212 VS 18147 Mercury wins! ---------- Comparing Mercury and Sheraton... 19212 VS 19342 Mercury wins! ---------- Comparing Mercury and Redison... 19212 VS 22841 Mercury wins! ---------- Comparing Mercury and Polonia... 23212 VS 23109 Polonia wins! ---------- Comparing Mercury and Merc Varsh... 15212 VS 24431 Mercury wins! ---------- Comparing Mercury and Sofitel... 25212 VS 25719 Mercury wins! ---------- Comparing Mercury and Varah Mar... 19212 VS 26268 Mercury wins! ---------- Comparing Mercury and Hotel... 23212 VS 28004 Mercury wins! ---------- Comparing Mercury and Hotel dristol... 29212 VS 29843 Mercury wins! ---------- Comparing Novotel and Sheraton... 26147 VS 19342 Sheraton wins! ---------- Comparing Novotel and Redison... 26147 VS 22841 Redison wins! ---------- Comparing Novotel and Polonia... 30147 VS 23109 Polonia wins! ---------- Comparing Novotel and Merc Varsh... 22147 VS 24431 Novotel wins! ---------- Comparing Novotel and Sofitel... 32147 VS 25719 Sofitel wins! ---------- Comparing Novotel and Varah Mar... 26147 VS 26268 Novotel wins! ---------- Comparing Novotel and Hotel... 30147 VS 28004 Hotel wins! ---------- Comparing Novotel and Hotel dristol... 36147 VS 29843 Hotel dristol wins! ---------- Comparing Sheraton and Redison... 19342 VS 22841 Sheraton wins! ---------- Comparing Sheraton and Polonia... 23342 VS 23109 Polonia wins! ---------- Comparing Sheraton and Merc Varsh... 15342 VS 24431 Sheraton wins! ---------- Comparing Sheraton and Sofitel... 25342 VS 25719 Sheraton wins! ---------- Comparing Sheraton and Varah Mar... 19342 VS 26268 Sheraton wins! ---------- Comparing Sheraton and Hotel... 23342 VS 28004 Sheraton wins! ---------- Comparing Sheraton and Hotel dristol... 29342 VS 29843 Sheraton wins! ---------- Comparing Redison and Polonia... 26841 VS 23109 Polonia wins! ---------- Comparing Redison and Merc Varsh... 18841 VS 24431 Redison wins! ---------- Comparing Redison and Sofitel... 28841 VS 25719 Sofitel wins! ---------- Comparing Redison and Varah Mar... 22841 VS 26268 Redison wins! ---------- Comparing Redison and Hotel... 26841 VS 28004 Redison wins! ---------- Comparing Redison and Hotel dristol... 32841 VS 29843 Hotel dristol wins! ---------- Comparing Polonia and Merc Varsh... 15109 VS 24431 Polonia wins! ---------- Comparing Polonia and Sofitel... 25109 VS 25719 Polonia wins! ---------- Comparing Polonia and Varah Mar... 19109 VS 26268 Polonia wins! ---------- Comparing Polonia and Hotel... 23109 VS 28004 Polonia wins! ---------- Comparing Polonia and Hotel dristol... 29109 VS 29843 Polonia wins! ---------- Comparing Merc Varsh and Sofitel... 34431 VS 25719 Sofitel wins! ---------- Comparing Merc Varsh and Varah Mar... 28431 VS 26268 Varah Mar wins! ---------- Comparing Merc Varsh and Hotel... 32431 VS 28004 Hotel wins! ---------- Comparing Merc Varsh and Hotel dristol... 38431 VS 29843 Hotel dristol wins! ---------- Comparing Sofitel and Varah Mar... 19719 VS 26268 Sofitel wins! ---------- Comparing Sofitel and Hotel... 23719 VS 28004 Sofitel wins! ---------- Comparing Sofitel and Hotel dristol... 29719 VS 29843 Sofitel wins! ---------- Comparing Varah Mar and Hotel... 30268 VS 28004 Hotel wins! ---------- Comparing Varah Mar and Hotel dristol... 36268 VS 29843 Hotel dristol wins! ---------- Comparing Hotel and Hotel dristol... 34004 VS 29843 Hotel dristol wins! ---------- ---------- Top: Polonia: 9 Mercury: 8 Sheraton: 7 Sofitel: 6 Hotel dristol: 5 Redison: 4 Hotel: 3 Novotel: 2 Varah Mar: 1 Merc Varsh: 0 ---------- Finalists: Polonia Mercury
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/tc5s0 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/tc5s0 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/tc5s0 on line 3
Process exited with code 255.