3v4l.org

run code in 300+ PHP versions simultaneously
<?php $hotels = [ ['Belair', 4, 8.4, 30950], ['Kamari', 4, 8.0, 39095], ['Katrin', 4, 8.4, 39514], ['sant', 4, 8.1, 40756], ['Eden', 4, 8.1, 41929], ['Amarhus', 5, 8.0, 44959], ['Esperas', 5, 8.1, 50823], ['Apolon', 4, 9.2, 54081], ['Rodos', 5, 9.0, 58968], ]; $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.20, 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 Belair and Kamari... 22950 VS 39095 Belair wins! ---------- Comparing Belair and Katrin... 30950 VS 39514 Belair wins! ---------- Comparing Belair and sant... 24950 VS 40756 Belair wins! ---------- Comparing Belair and Eden... 24950 VS 41929 Belair wins! ---------- Comparing Belair and Amarhus... 26950 VS 44959 Belair wins! ---------- Comparing Belair and Esperas... 28950 VS 50823 Belair wins! ---------- Comparing Belair and Apolon... 46950 VS 54081 Belair wins! ---------- Comparing Belair and Rodos... 46950 VS 58968 Belair wins! ---------- Comparing Kamari and Katrin... 47095 VS 39514 Katrin wins! ---------- Comparing Kamari and sant... 41095 VS 40756 sant wins! ---------- Comparing Kamari and Eden... 41095 VS 41929 Kamari wins! ---------- Comparing Kamari and Amarhus... 43095 VS 44959 Kamari wins! ---------- Comparing Kamari and Esperas... 45095 VS 50823 Kamari wins! ---------- Comparing Kamari and Apolon... 63095 VS 54081 Apolon wins! ---------- Comparing Kamari and Rodos... 63095 VS 58968 Rodos wins! ---------- Comparing Katrin and sant... 33514 VS 40756 Katrin wins! ---------- Comparing Katrin and Eden... 33514 VS 41929 Katrin wins! ---------- Comparing Katrin and Amarhus... 35514 VS 44959 Katrin wins! ---------- Comparing Katrin and Esperas... 37514 VS 50823 Katrin wins! ---------- Comparing Katrin and Apolon... 55514 VS 54081 Apolon wins! ---------- Comparing Katrin and Rodos... 55514 VS 58968 Katrin wins! ---------- Comparing sant and Eden... 40756 VS 41929 sant wins! ---------- Comparing sant and Amarhus... 42756 VS 44959 sant wins! ---------- Comparing sant and Esperas... 44756 VS 50823 sant wins! ---------- Comparing sant and Apolon... 62756 VS 54081 Apolon wins! ---------- Comparing sant and Rodos... 62756 VS 58968 Rodos wins! ---------- Comparing Eden and Amarhus... 43929 VS 44959 Eden wins! ---------- Comparing Eden and Esperas... 45929 VS 50823 Eden wins! ---------- Comparing Eden and Apolon... 63929 VS 54081 Apolon wins! ---------- Comparing Eden and Rodos... 63929 VS 58968 Rodos wins! ---------- Comparing Amarhus and Esperas... 46959 VS 50823 Amarhus wins! ---------- Comparing Amarhus and Apolon... 64959 VS 54081 Apolon wins! ---------- Comparing Amarhus and Rodos... 64959 VS 58968 Rodos wins! ---------- Comparing Esperas and Apolon... 68823 VS 54081 Apolon wins! ---------- Comparing Esperas and Rodos... 68823 VS 58968 Rodos wins! ---------- Comparing Apolon and Rodos... 54081 VS 58968 Apolon wins! ---------- ---------- Top: Belair: 8 Apolon: 7 Katrin: 6 Rodos: 5 sant: 4 Kamari: 3 Eden: 2 Amarhus: 1 Esperas: 0 ---------- Finalists: Belair Apolon
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/ltM0F 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/ltM0F on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/ltM0F on line 3
Process exited with code 255.

preferences:
279.68 ms | 401 KiB | 315 Q