3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Cala', 3, 8.7, 6000], ['Ocean', 3, 8.2, 6150], ['Orchid', 3, 8.0, 7200], ['Ya', 3, 8.7, 6950], ['Chaba', 3, 8.2, 7120], ]; $totalHotelsNumber = 2; $starCoef = 0.2; $ratingCoef = 2000; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[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 += $ratingToCompensate; $ratingDifference = $rating-$hotels[$j][2]; $priceToCompensate = $ratingDifference*$ratingCoef; $price -= $priceToCompensate; echo $price.' VS '.$hotels[$j][2]."\r\n"; if ( $price > $hotels[$j][2] ) { 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 $hotelA[4]-$hotelB[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, 7.0.0 - 7.1.0
Comparing Cala and Ocean... Notice: Undefined variable: rating in /in/OkRnb on line 26 Notice: Undefined variable: price in /in/OkRnb on line 30 16400 VS 8.2 Cala wins! Notice: Undefined offset: 4 in /in/OkRnb on line 35 ---------- Comparing Cala and Orchid... 32400 VS 8 Cala wins! ---------- Comparing Cala and Ya... 49800 VS 8.7 Cala wins! ---------- Comparing Cala and ... 48600 VS Cala wins! ---------- Comparing Ocean and Orchid... 63400 VS 8 Ocean wins! Notice: Undefined offset: 4 in /in/OkRnb on line 35 ---------- Comparing Ocean and Ya... 79600 VS 8.7 Ocean wins! ---------- Comparing Ocean and ... 77200 VS Ocean wins! ---------- Comparing Orchid and Ya... 92200 VS 8.7 Orchid wins! Notice: Undefined offset: 4 in /in/OkRnb on line 35 ---------- Comparing Orchid and ... 88600 VS Orchid wins! ---------- Comparing Ya and ... 83800 VS Ya wins! Notice: Undefined offset: 4 in /in/OkRnb on line 35 ---------- ---------- Top: : Ya: 1 Orchid: 2 Ocean: 3 Cala: 4 ---------- Finalists: Ya
Output for hhvm-3.10.0 - 3.12.0
Comparing Cala and Ocean... 16400 VS 8.2 Cala wins! ---------- Comparing Cala and Orchid... 32400 VS 8 Cala wins! ---------- Comparing Cala and Ya... 49800 VS 8.7 Cala wins! ---------- Comparing Cala and ... 48600 VS Cala wins! ---------- Comparing Ocean and Orchid... 63400 VS 8 Ocean wins! ---------- Comparing Ocean and Ya... 79600 VS 8.7 Ocean wins! ---------- Comparing Ocean and ... 77200 VS Ocean wins! ---------- Comparing Orchid and Ya... 92200 VS 8.7 Orchid wins! ---------- Comparing Orchid and ... 88600 VS Orchid wins! ---------- Comparing Ya and ... 83800 VS Ya wins! ---------- ---------- Top: : Ya: 1 Orchid: 2 Ocean: 3 Cala: 4 ---------- Finalists: Ya
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/OkRnb 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/OkRnb on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/OkRnb on line 3
Process exited with code 255.