3v4l.org

run code in 300+ PHP versions simultaneously
<?php $hotels = [ ['Issara Resort', 3, 8.2, 4550], ['Cata', 3, 8.7, 5921], ['Sun', 3, 8.6, 5970], ['Ocean', 3, 8.2, 6371], ['Orchid', 3, 8.0, 6745], ['Ya', 3, 8.7, 6745], ['Phuket', 3, 8.2, 7420], ['Baa', 3, 8.0, 8544], ['The', 3, 8.4, 8994], ['Bamboo', 3, 8.5, 8994], ['Cata', 4, 8.0, 9376], ['Shugar', 3, 8.1, 9443], ['Phuket B', 3, 8.7, 10493], ['Villa', 3, 8.7, 11242], ['Centara', 4, 8.2, 11247], ['The old', 4, 8.2, 11992], ['Cantari', 4, 8.6, 11992], ['By', 3, 8.4, 11992], ['Shugar m', 3, 8.5, 12141], ['Panwa', 4, 8.1, 12179], ]; $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; $price = round($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"; }

preferences:
37.67 ms | 402 KiB | 5 Q