3v4l.org

run code in 300+ PHP versions simultaneously
<?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', ]; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } $starCoefOptions = range(0.02, 3, 0.02); $ratingCoefOptions = range(100, 10000, 100); 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 git.master, git.master_jit, rfc.property-hooks
$starCoef = 0.02 $ratingCoef = 100 $starCoef = 0.02 $ratingCoef = 200 $starCoef = 0.02 $ratingCoef = 300 $starCoef = 0.02 $ratingCoef = 400 $starCoef = 0.02 $ratingCoef = 500 $starCoef = 0.02 $ratingCoef = 600 $starCoef = 0.04 $ratingCoef = 100 $starCoef = 0.04 $ratingCoef = 200 $starCoef = 0.04 $ratingCoef = 300 $starCoef = 0.04 $ratingCoef = 400 $starCoef = 0.04 $ratingCoef = 500 $starCoef = 0.06 $ratingCoef = 100 $starCoef = 0.06 $ratingCoef = 200 $starCoef = 0.06 $ratingCoef = 300 $starCoef = 0.06 $ratingCoef = 400 $starCoef = 0.08 $ratingCoef = 100 $starCoef = 0.08 $ratingCoef = 200 $starCoef = 0.08 $ratingCoef = 300 $starCoef = 0.08 $ratingCoef = 400 $starCoef = 0.1 $ratingCoef = 100 $starCoef = 0.1 $ratingCoef = 200 $starCoef = 0.1 $ratingCoef = 300 $starCoef = 0.12 $ratingCoef = 100 $starCoef = 0.12 $ratingCoef = 200 $starCoef = 0.12 $ratingCoef = 300 $starCoef = 0.14 $ratingCoef = 100 $starCoef = 0.14 $ratingCoef = 200 $starCoef = 0.14 $ratingCoef = 300 $starCoef = 0.16 $ratingCoef = 100 $starCoef = 0.16 $ratingCoef = 200 $starCoef = 0.16 $ratingCoef = 300 $starCoef = 0.18 $ratingCoef = 100 $starCoef = 0.18 $ratingCoef = 200 $starCoef = 0.2 $ratingCoef = 100 $starCoef = 0.2 $ratingCoef = 200 $starCoef = 0.22 $ratingCoef = 100 $starCoef = 0.22 $ratingCoef = 200 $starCoef = 0.24 $ratingCoef = 100 $starCoef = 0.24 $ratingCoef = 200 $starCoef = 0.26 $ratingCoef = 100 $starCoef = 0.26 $ratingCoef = 200 $starCoef = 0.28 $ratingCoef = 100 $starCoef = 0.28 $ratingCoef = 200 $starCoef = 0.3 $ratingCoef = 100 $starCoef = 0.32 $ratingCoef = 100 $starCoef = 0.34 $ratingCoef = 100 $starCoef = 0.36 $ratingCoef = 100 $starCoef = 0.38 $ratingCoef = 100 $starCoef = 0.4 $ratingCoef = 100 $starCoef = 0.42 $ratingCoef = 100 $starCoef = 0.44 $ratingCoef = 100 $starCoef = 0.46 $ratingCoef = 100 $starCoef = 0.48 $ratingCoef = 100 $starCoef = 0.5 $ratingCoef = 100 $starCoef = 0.52 $ratingCoef = 100 $starCoef = 0.54 $ratingCoef = 100 $starCoef = 0.56 $ratingCoef = 100 $starCoef = 0.58 $ratingCoef = 100 $starCoef = 0.6 $ratingCoef = 100 $starCoef = 0.62 $ratingCoef = 100 $starCoef = 0.64 $ratingCoef = 100 $starCoef = 0.66 $ratingCoef = 100 $starCoef = 0.68 $ratingCoef = 100

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
49.27 ms | 409 KiB | 8 Q