3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Kvatera', 0, 8.4, 11762], ['Loft', 0, 8.9, 12154], ['Apartment', 0, 8.5, 12467], ['Hos', 0, 8.0, 13252], ['Apart Cent', 0, 9.0, 13778], ['Enbeve', 0, 8.4, 13778], ['Loft sen', 0, 8.8, 13806], ['Dream', 0, 9.1, 14114], ]; $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 Kvatera and Loft... 21762 VS 12154 Loft wins! ---------- Comparing Kvatera and Apartment... 13762 VS 12467 Apartment wins! ---------- Comparing Kvatera and Hos... 3762 VS 13252 Kvatera wins! ---------- Comparing Kvatera and Apart Cent... 23762 VS 13778 Apart Cent wins! ---------- Comparing Kvatera and Enbeve... 11762 VS 13778 Kvatera wins! ---------- Comparing Kvatera and Loft sen... 19762 VS 13806 Loft sen wins! ---------- Comparing Kvatera and Dream... 25762 VS 14114 Dream wins! ---------- Comparing Loft and Apartment... 4154 VS 12467 Loft wins! ---------- Comparing Loft and Hos... -5846 VS 13252 Loft wins! ---------- Comparing Loft and Apart Cent... 14154 VS 13778 Apart Cent wins! ---------- Comparing Loft and Enbeve... 2154 VS 13778 Loft wins! ---------- Comparing Loft and Loft sen... 10154 VS 13806 Loft wins! ---------- Comparing Loft and Dream... 16154 VS 14114 Dream wins! ---------- Comparing Apartment and Hos... 2467 VS 13252 Apartment wins! ---------- Comparing Apartment and Apart Cent... 22467 VS 13778 Apart Cent wins! ---------- Comparing Apartment and Enbeve... 10467 VS 13778 Apartment wins! ---------- Comparing Apartment and Loft sen... 18467 VS 13806 Loft sen wins! ---------- Comparing Apartment and Dream... 24467 VS 14114 Dream wins! ---------- Comparing Hos and Apart Cent... 33252 VS 13778 Apart Cent wins! ---------- Comparing Hos and Enbeve... 21252 VS 13778 Enbeve wins! ---------- Comparing Hos and Loft sen... 29252 VS 13806 Loft sen wins! ---------- Comparing Hos and Dream... 35252 VS 14114 Dream wins! ---------- Comparing Apart Cent and Enbeve... 1778 VS 13778 Apart Cent wins! ---------- Comparing Apart Cent and Loft sen... 9778 VS 13806 Apart Cent wins! ---------- Comparing Apart Cent and Dream... 15778 VS 14114 Dream wins! ---------- Comparing Enbeve and Loft sen... 21778 VS 13806 Loft sen wins! ---------- Comparing Enbeve and Dream... 27778 VS 14114 Dream wins! ---------- Comparing Loft sen and Dream... 19806 VS 14114 Dream wins! ---------- ---------- Top: Dream: 7 Apart Cent: 6 Loft: 5 Loft sen: 4 Apartment: 3 Kvatera: 2 Enbeve: 1 Hos: 0 ---------- Finalists: Dream Apart Cent
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/pcCi3 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/pcCi3 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/pcCi3 on line 3
Process exited with code 255.