3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $hotels = [ ['Auditor', 1, 8.4, 21176], ['Everest', 2, 8.2, 21176], ['Guiboli', 2, 8.0, 21781], ['Florida', 2, 8.0, 22154], ['Guiliano', 2, 8.5, 23033], ['Marielen', 2, 8.3, 24015], ['max', 3, 8.2, 24253], ['Pratti', 2, 8.1, 24434], ['Everest inn', 2, 8.1, 24807], ['Olbeminele', 3, 8.4, 24965], ]; $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"; }
Output for 5.4.0 - 7.1.0
Comparing Auditor and Everest... 21176 VS 21176 Everest wins! ---------- Comparing Auditor and Guiboli... 17176 VS 21781 Auditor wins! ---------- Comparing Auditor and Florida... 17176 VS 22154 Auditor wins! ---------- Comparing Auditor and Guiliano... 27176 VS 23033 Guiliano wins! ---------- Comparing Auditor and Marielen... 23176 VS 24015 Auditor wins! ---------- Comparing Auditor and max... 25176 VS 24253 max wins! ---------- Comparing Auditor and Pratti... 19176 VS 24434 Auditor wins! ---------- Comparing Auditor and Everest inn... 19176 VS 24807 Auditor wins! ---------- Comparing Auditor and Olbeminele... 29176 VS 24965 Olbeminele wins! ---------- Comparing Everest and Guiboli... 17176 VS 21781 Everest wins! ---------- Comparing Everest and Florida... 17176 VS 22154 Everest wins! ---------- Comparing Everest and Guiliano... 27176 VS 23033 Guiliano wins! ---------- Comparing Everest and Marielen... 23176 VS 24015 Everest wins! ---------- Comparing Everest and max... 25176 VS 24253 max wins! ---------- Comparing Everest and Pratti... 19176 VS 24434 Everest wins! ---------- Comparing Everest and Everest inn... 19176 VS 24807 Everest wins! ---------- Comparing Everest and Olbeminele... 29176 VS 24965 Olbeminele wins! ---------- Comparing Guiboli and Florida... 21781 VS 22154 Guiboli wins! ---------- Comparing Guiboli and Guiliano... 31781 VS 23033 Guiliano wins! ---------- Comparing Guiboli and Marielen... 27781 VS 24015 Marielen wins! ---------- Comparing Guiboli and max... 29781 VS 24253 max wins! ---------- Comparing Guiboli and Pratti... 23781 VS 24434 Guiboli wins! ---------- Comparing Guiboli and Everest inn... 23781 VS 24807 Guiboli wins! ---------- Comparing Guiboli and Olbeminele... 33781 VS 24965 Olbeminele wins! ---------- Comparing Florida and Guiliano... 32154 VS 23033 Guiliano wins! ---------- Comparing Florida and Marielen... 28154 VS 24015 Marielen wins! ---------- Comparing Florida and max... 30154 VS 24253 max wins! ---------- Comparing Florida and Pratti... 24154 VS 24434 Florida wins! ---------- Comparing Florida and Everest inn... 24154 VS 24807 Florida wins! ---------- Comparing Florida and Olbeminele... 34154 VS 24965 Olbeminele wins! ---------- Comparing Guiliano and Marielen... 19033 VS 24015 Guiliano wins! ---------- Comparing Guiliano and max... 21033 VS 24253 Guiliano wins! ---------- Comparing Guiliano and Pratti... 15033 VS 24434 Guiliano wins! ---------- Comparing Guiliano and Everest inn... 15033 VS 24807 Guiliano wins! ---------- Comparing Guiliano and Olbeminele... 25033 VS 24965 Olbeminele wins! ---------- Comparing Marielen and max... 26015 VS 24253 max wins! ---------- Comparing Marielen and Pratti... 20015 VS 24434 Marielen wins! ---------- Comparing Marielen and Everest inn... 20015 VS 24807 Marielen wins! ---------- Comparing Marielen and Olbeminele... 30015 VS 24965 Olbeminele wins! ---------- Comparing max and Pratti... 18253 VS 24434 max wins! ---------- Comparing max and Everest inn... 18253 VS 24807 max wins! ---------- Comparing max and Olbeminele... 28253 VS 24965 Olbeminele wins! ---------- Comparing Pratti and Everest inn... 24434 VS 24807 Pratti wins! ---------- Comparing Pratti and Olbeminele... 34434 VS 24965 Olbeminele wins! ---------- Comparing Everest inn and Olbeminele... 34807 VS 24965 Olbeminele wins! ---------- ---------- Top: Olbeminele: 9 Guiliano: 8 max: 7 Everest: 6 Auditor: 5 Marielen: 4 Guiboli: 3 Florida: 2 Pratti: 1 Everest inn: 0 ---------- Finalists: Olbeminele Guiliano
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/OVbKe 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/OVbKe on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/OVbKe on line 3
Process exited with code 255.