3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Tsambika', 2, 8.1, 9122], ['Tivoli', 2, 8.1, 11403], ['Radian', 2, 8.4, 17267], ['Filmar', 2, 8.4, 18510], ['Mon', 2, 8.7, 19222], ['Liristik', 0, 9.1, 20851], ['Zoyas', 3, 8.8, 22362], ['Nirvana', 3, 8.7, 24434], ]; $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 Tsambika and Tivoli... 9122 VS 11403 Tsambika wins! ---------- Comparing Tsambika and Radian... 15122 VS 17267 Tsambika wins! ---------- Comparing Tsambika and Filmar... 15122 VS 18510 Tsambika wins! ---------- Comparing Tsambika and Mon... 21122 VS 19222 Mon wins! ---------- Comparing Tsambika and Liristik... 21122 VS 20851 Liristik wins! ---------- Comparing Tsambika and Zoyas... 27122 VS 22362 Zoyas wins! ---------- Comparing Tsambika and Nirvana... 25122 VS 24434 Nirvana wins! ---------- Comparing Tivoli and Radian... 17403 VS 17267 Radian wins! ---------- Comparing Tivoli and Filmar... 17403 VS 18510 Tivoli wins! ---------- Comparing Tivoli and Mon... 23403 VS 19222 Mon wins! ---------- Comparing Tivoli and Liristik... 23403 VS 20851 Liristik wins! ---------- Comparing Tivoli and Zoyas... 29403 VS 22362 Zoyas wins! ---------- Comparing Tivoli and Nirvana... 27403 VS 24434 Nirvana wins! ---------- Comparing Radian and Filmar... 17267 VS 18510 Radian wins! ---------- Comparing Radian and Mon... 23267 VS 19222 Mon wins! ---------- Comparing Radian and Liristik... 23267 VS 20851 Liristik wins! ---------- Comparing Radian and Zoyas... 29267 VS 22362 Zoyas wins! ---------- Comparing Radian and Nirvana... 27267 VS 24434 Nirvana wins! ---------- Comparing Filmar and Mon... 24510 VS 19222 Mon wins! ---------- Comparing Filmar and Liristik... 24510 VS 20851 Liristik wins! ---------- Comparing Filmar and Zoyas... 30510 VS 22362 Zoyas wins! ---------- Comparing Filmar and Nirvana... 28510 VS 24434 Nirvana wins! ---------- Comparing Mon and Liristik... 19222 VS 20851 Mon wins! ---------- Comparing Mon and Zoyas... 25222 VS 22362 Zoyas wins! ---------- Comparing Mon and Nirvana... 23222 VS 24434 Mon wins! ---------- Comparing Liristik and Zoyas... 26851 VS 22362 Zoyas wins! ---------- Comparing Liristik and Nirvana... 24851 VS 24434 Nirvana wins! ---------- Comparing Zoyas and Nirvana... 20362 VS 24434 Zoyas wins! ---------- ---------- Top: Zoyas: 7 Mon: 6 Nirvana: 5 Liristik: 4 Tsambika: 3 Radian: 2 Tivoli: 1 Filmar: 0 ---------- Finalists: Zoyas Mon
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/q8ht3 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/q8ht3 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/q8ht3 on line 3
Process exited with code 255.