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], ]; $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; echo $priceToCompensate."\r\n"; $price = $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 git.master, git.master_jit, rfc.property-hooks
Comparing Cala and Ocean... 10000 -4000 VS 6150 Ocean wins! ---------- Comparing Cala and Orchid... 14000 -8000 VS 7200 Orchid wins! ---------- Comparing Cala and Ya... 4000 2000 VS 6950 Ya wins! ---------- Comparing Cala and Chaba... 10000 -4000 VS 7120 Chaba wins! ---------- Comparing Ocean and Orchid... 4000 2150 VS 7200 Orchid wins! ---------- Comparing Ocean and Ya... -6000 12150 VS 6950 Ocean wins! ---------- Comparing Ocean and Chaba... 0 6150 VS 7120 Chaba wins! ---------- Comparing Orchid and Ya... -10000 17200 VS 6950 Orchid wins! ---------- Comparing Orchid and Chaba... -4000 11200 VS 7120 Orchid wins! ---------- Comparing Ya and Chaba... 6000 949.99999999999 VS 7120 Chaba wins! ---------- ---------- Top: Orchid: 4 Chaba: 3 Ocean: 2 Ya: 1 Cala: 0 ---------- Finalists: Orchid Chaba

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:
56.6 ms | 403 KiB | 8 Q