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', 4, 8.3, 6950], ['Chaba', 3, 8.2, 7120], ]; $top = [ 'Cala', 'Ocean', 'Ya', ]; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } $starCoefOptions = range(0, 5, 0.1); $ratingCoefOptions = range(20, 10000, 20); foreach ( $starCoefOptions as $starCoef ) { foreach ( $ratingCoefOptions as $ratingCoef ) { $topGenerated = buildTop($hotels, $starCoef, $ratingCoef); $topGenerated = array_slice($topGenerated, 0, count($top)); if ( $topGenerated === $top ) { echo '$starCoef = '.$starCoef."\r\n"; echo '$ratingCoef = '.$ratingCoef."\r\n"; echo "\r\n"; } } } function buildTop($hotels, $starCoef, $ratingCoef) { for ( $i=0; $i<count($hotels); $i++ ) { for ( $j=$i+1; $j<count($hotels); $j++ ) { $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); if ( $price < $hotels[$j][3] ) { $hotels[$i][4]++; } else { $hotels[$j][4]++; } } } usort($hotels, function($hotelA, $hotelB){ return $hotelB[4]-$hotelA[4]; }); return array_map(function($hotel){ return $hotel[0]; }, $hotels); }
Output for 5.4.0 - 7.1.0
$starCoef = 0 $ratingCoef = 20 $starCoef = 0 $ratingCoef = 40 $starCoef = 0 $ratingCoef = 60 $starCoef = 0 $ratingCoef = 80 $starCoef = 0 $ratingCoef = 100 $starCoef = 0 $ratingCoef = 120 $starCoef = 0 $ratingCoef = 140 $starCoef = 0 $ratingCoef = 160 $starCoef = 0 $ratingCoef = 180 $starCoef = 0 $ratingCoef = 200 $starCoef = 0 $ratingCoef = 220 $starCoef = 0 $ratingCoef = 240 $starCoef = 0 $ratingCoef = 260 $starCoef = 0 $ratingCoef = 280 $starCoef = 0 $ratingCoef = 300 $starCoef = 0 $ratingCoef = 320 $starCoef = 0 $ratingCoef = 340 $starCoef = 0 $ratingCoef = 360 $starCoef = 0 $ratingCoef = 380 $starCoef = 0 $ratingCoef = 400 $starCoef = 0 $ratingCoef = 420 $starCoef = 0 $ratingCoef = 440 $starCoef = 0 $ratingCoef = 460 $starCoef = 0 $ratingCoef = 480 $starCoef = 0 $ratingCoef = 500 $starCoef = 0 $ratingCoef = 520 $starCoef = 0 $ratingCoef = 540 $starCoef = 0 $ratingCoef = 560 $starCoef = 0 $ratingCoef = 580 $starCoef = 0 $ratingCoef = 600 $starCoef = 0 $ratingCoef = 620 $starCoef = 0 $ratingCoef = 640 $starCoef = 0 $ratingCoef = 660 $starCoef = 0 $ratingCoef = 680 $starCoef = 0 $ratingCoef = 700 $starCoef = 0 $ratingCoef = 720 $starCoef = 0 $ratingCoef = 740 $starCoef = 0 $ratingCoef = 760 $starCoef = 0 $ratingCoef = 780 $starCoef = 0.1 $ratingCoef = 20 $starCoef = 0.1 $ratingCoef = 40 $starCoef = 0.1 $ratingCoef = 60 $starCoef = 0.1 $ratingCoef = 80 $starCoef = 0.1 $ratingCoef = 100 $starCoef = 0.1 $ratingCoef = 120 $starCoef = 0.1 $ratingCoef = 140 $starCoef = 0.1 $ratingCoef = 160 $starCoef = 0.1 $ratingCoef = 180 $starCoef = 0.1 $ratingCoef = 200 $starCoef = 0.1 $ratingCoef = 220 $starCoef = 0.1 $ratingCoef = 240 $starCoef = 0.1 $ratingCoef = 260 $starCoef = 0.1 $ratingCoef = 280 $starCoef = 0.1 $ratingCoef = 300 $starCoef = 0.1 $ratingCoef = 320 $starCoef = 0.1 $ratingCoef = 340 $starCoef = 0.1 $ratingCoef = 360 $starCoef = 0.1 $ratingCoef = 380 $starCoef = 0.2 $ratingCoef = 20 $starCoef = 0.2 $ratingCoef = 40 $starCoef = 0.2 $ratingCoef = 60 $starCoef = 0.2 $ratingCoef = 80 $starCoef = 0.2 $ratingCoef = 100 $starCoef = 0.2 $ratingCoef = 120 $starCoef = 0.2 $ratingCoef = 140 $starCoef = 0.2 $ratingCoef = 160 $starCoef = 0.2 $ratingCoef = 180 $starCoef = 0.2 $ratingCoef = 200 $starCoef = 0.2 $ratingCoef = 220 $starCoef = 0.2 $ratingCoef = 240 $starCoef = 0.2 $ratingCoef = 260 $starCoef = 0.3 $ratingCoef = 20 $starCoef = 0.3 $ratingCoef = 40 $starCoef = 0.3 $ratingCoef = 60 $starCoef = 0.3 $ratingCoef = 80 $starCoef = 0.3 $ratingCoef = 100 $starCoef = 0.3 $ratingCoef = 120 $starCoef = 0.3 $ratingCoef = 140 $starCoef = 0.3 $ratingCoef = 160 $starCoef = 0.3 $ratingCoef = 180 $starCoef = 0.4 $ratingCoef = 20 $starCoef = 0.4 $ratingCoef = 40 $starCoef = 0.4 $ratingCoef = 60 $starCoef = 0.4 $ratingCoef = 80 $starCoef = 0.4 $ratingCoef = 100 $starCoef = 0.4 $ratingCoef = 120 $starCoef = 0.4 $ratingCoef = 140 $starCoef = 0.5 $ratingCoef = 20 $starCoef = 0.5 $ratingCoef = 40 $starCoef = 0.5 $ratingCoef = 60 $starCoef = 0.5 $ratingCoef = 80 $starCoef = 0.5 $ratingCoef = 100 $starCoef = 0.5 $ratingCoef = 120 $starCoef = 0.6 $ratingCoef = 20 $starCoef = 0.6 $ratingCoef = 40 $starCoef = 0.6 $ratingCoef = 60 $starCoef = 0.6 $ratingCoef = 80 $starCoef = 0.6 $ratingCoef = 100 $starCoef = 0.7 $ratingCoef = 20 $starCoef = 0.7 $ratingCoef = 40 $starCoef = 0.7 $ratingCoef = 60 $starCoef = 0.7 $ratingCoef = 80 $starCoef = 0.8 $ratingCoef = 20 $starCoef = 0.8 $ratingCoef = 40 $starCoef = 0.8 $ratingCoef = 60 $starCoef = 0.8 $ratingCoef = 80 $starCoef = 0.9 $ratingCoef = 20 $starCoef = 0.9 $ratingCoef = 40 $starCoef = 0.9 $ratingCoef = 60 $starCoef = 1 $ratingCoef = 20 $starCoef = 1 $ratingCoef = 40 $starCoef = 1 $ratingCoef = 60 $starCoef = 1.1 $ratingCoef = 20 $starCoef = 1.1 $ratingCoef = 40 $starCoef = 1.1 $ratingCoef = 60 $starCoef = 1.2 $ratingCoef = 20 $starCoef = 1.2 $ratingCoef = 40 $starCoef = 1.2 $ratingCoef = 60 $starCoef = 1.3 $ratingCoef = 20 $starCoef = 1.3 $ratingCoef = 40 $starCoef = 1.4 $ratingCoef = 20 $starCoef = 1.4 $ratingCoef = 40 $starCoef = 1.5 $ratingCoef = 20 $starCoef = 1.5 $ratingCoef = 40 $starCoef = 1.6 $ratingCoef = 20 $starCoef = 1.6 $ratingCoef = 40 $starCoef = 1.7 $ratingCoef = 20 $starCoef = 1.7 $ratingCoef = 40 $starCoef = 1.8 $ratingCoef = 20 $starCoef = 1.8 $ratingCoef = 40 $starCoef = 1.9 $ratingCoef = 20 $starCoef = 2 $ratingCoef = 20 $starCoef = 2.1 $ratingCoef = 20 $starCoef = 2.2 $ratingCoef = 20 $starCoef = 2.3 $ratingCoef = 20 $starCoef = 2.4 $ratingCoef = 20 $starCoef = 2.5 $ratingCoef = 20 $starCoef = 2.6 $ratingCoef = 20 $starCoef = 2.7 $ratingCoef = 20 $starCoef = 2.8 $ratingCoef = 20 $starCoef = 2.9 $ratingCoef = 20 $starCoef = 3 $ratingCoef = 20 $starCoef = 3.1 $ratingCoef = 20 $starCoef = 3.2 $ratingCoef = 20 $starCoef = 3.3 $ratingCoef = 20 $starCoef = 3.4 $ratingCoef = 20 $starCoef = 3.5 $ratingCoef = 20 $starCoef = 3.6 $ratingCoef = 20 $starCoef = 3.7 $ratingCoef = 20 $starCoef = 3.8 $ratingCoef = 20
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/9Djaq 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/9Djaq on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/9Djaq on line 3
Process exited with code 255.