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', 'Ya', 'Ocean', 'Chaba', ]; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } $starCoefOptions = range(0.1, 5, 0.1); $ratingCoefOptions = range(20, 10000, 20); $results = []; foreach ( $starCoefOptions as $starCoef ) { foreach ( $ratingCoefOptions as $ratingCoef ) { $topGenerated = buildTop($hotels, $starCoef, $ratingCoef); $topGenerated = array_slice($topGenerated, 0, count($top)); if ( $topGenerated === $top ) { $results[strval($starCoef)][] = $ratingCoef; } } } foreach ( $results as $starCoef=>$ratingCoefs ) { echo $starCoef.': '.min($ratingCoefs).' - '.max($ratingCoefs)."\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
0.1: 400 - 10000 0.2: 280 - 10000 0.3: 200 - 10000 0.4: 160 - 10000 0.5: 140 - 940 0.6: 120 - 460 0.7: 100 - 300 0.8: 100 - 220 0.9: 80 - 180 1: 80 - 140 1.1: 80 - 120 1.2: 80 - 100 1.3: 60 - 100 1.4: 60 - 80 1.5: 60 - 80 1.6: 60 - 60 1.7: 60 - 60 1.8: 60 - 60 1.9: 40 - 60 2: 40 - 40 2.1: 40 - 40 2.2: 40 - 40 2.3: 40 - 40 2.4: 40 - 40 2.5: 40 - 40 2.6: 40 - 40 2.7: 40 - 40 3.9: 20 - 20 4: 20 - 20 4.1: 20 - 20 4.2: 20 - 20 4.3: 20 - 20 4.4: 20 - 20 4.5: 20 - 20 4.6: 20 - 20 4.7: 20 - 20 4.8: 20 - 20 4.9: 20 - 20 5: 20 - 20

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:
36.84 ms | 402 KiB | 8 Q