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', 3, 8.7, 6950], ['Chaba', 3, 8.2, 7120], ]; $totalHotelsNumber = 2; $starCoef = 0.2; $ratingCoef = 2000; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[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]; $priceToCompensate = $ratingDifference*$ratingCoef; $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 $hotelA[4]-$hotelB[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 8.3.0 - 8.3.6
Comparing Cala and Ocean... 5000 VS 6150 Ocean wins! Warning: Undefined array key 4 in /in/KLaZr on line 38 ---------- Comparing Cala and Orchid... 4600 VS 7200 Orchid wins! Warning: Undefined array key 4 in /in/KLaZr on line 38 ---------- Comparing Cala and Ya... 6000 VS 6950 Ya wins! Warning: Undefined array key 4 in /in/KLaZr on line 38 ---------- Warning: Trying to access array offset on int in /in/KLaZr on line 22 Comparing Cala and ... Warning: Trying to access array offset on int in /in/KLaZr on line 24 Warning: Trying to access array offset on int in /in/KLaZr on line 28 Warning: Trying to access array offset on int in /in/KLaZr on line 32 -12600 VS Warning: Trying to access array offset on int in /in/KLaZr on line 33 Cala wins! Warning: Undefined array key 4 in /in/KLaZr on line 35 ---------- Comparing Ocean and Orchid... 5750 VS 7200 Orchid wins! ---------- Comparing Ocean and Ya... 7150 VS 6950 Ocean wins! ---------- Warning: Trying to access array offset on int in /in/KLaZr on line 22 Comparing Ocean and ... Warning: Trying to access array offset on int in /in/KLaZr on line 24 Warning: Trying to access array offset on int in /in/KLaZr on line 28 Warning: Trying to access array offset on int in /in/KLaZr on line 32 -11450 VS Warning: Trying to access array offset on int in /in/KLaZr on line 33 Ocean wins! ---------- Comparing Orchid and Ya... 8600 VS 6950 Orchid wins! ---------- Warning: Trying to access array offset on int in /in/KLaZr on line 22 Comparing Orchid and ... Warning: Trying to access array offset on int in /in/KLaZr on line 24 Warning: Trying to access array offset on int in /in/KLaZr on line 28 Warning: Trying to access array offset on int in /in/KLaZr on line 32 -10000 VS Warning: Trying to access array offset on int in /in/KLaZr on line 33 Orchid wins! ---------- Warning: Trying to access array offset on int in /in/KLaZr on line 22 Comparing Ya and ... Warning: Trying to access array offset on int in /in/KLaZr on line 24 Warning: Trying to access array offset on int in /in/KLaZr on line 28 Warning: Trying to access array offset on int in /in/KLaZr on line 32 -11650 VS Warning: Trying to access array offset on int in /in/KLaZr on line 33 Ya wins! ---------- Warning: Trying to access array offset on int in /in/KLaZr on line 46 Warning: Trying to access array offset on int in /in/KLaZr on line 46 Warning: Trying to access array offset on int in /in/KLaZr on line 46 Warning: Trying to access array offset on int in /in/KLaZr on line 46 ---------- Top: Warning: Trying to access array offset on int in /in/KLaZr on line 53 Warning: Trying to access array offset on int in /in/KLaZr on line 53 : Cala: 1 Ya: 2 Ocean: 3 Orchid: 4 ---------- Finalists: Warning: Trying to access array offset on int in /in/KLaZr on line 60 Cala
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Comparing Cala and Ocean... 5000 VS 6150 Ocean wins! Warning: Undefined array key 4 in /in/KLaZr on line 38 ---------- Comparing Cala and Orchid... 4600 VS 7200 Orchid wins! Warning: Undefined array key 4 in /in/KLaZr on line 38 ---------- Comparing Cala and Ya... 6000 VS 6950 Ya wins! Warning: Undefined array key 4 in /in/KLaZr on line 38 ---------- Warning: Trying to access array offset on value of type int in /in/KLaZr on line 22 Comparing Cala and ... Warning: Trying to access array offset on value of type int in /in/KLaZr on line 24 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 28 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 32 -12600 VS Warning: Trying to access array offset on value of type int in /in/KLaZr on line 33 Cala wins! Warning: Undefined array key 4 in /in/KLaZr on line 35 ---------- Comparing Ocean and Orchid... 5750 VS 7200 Orchid wins! ---------- Comparing Ocean and Ya... 7150 VS 6950 Ocean wins! ---------- Warning: Trying to access array offset on value of type int in /in/KLaZr on line 22 Comparing Ocean and ... Warning: Trying to access array offset on value of type int in /in/KLaZr on line 24 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 28 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 32 -11450 VS Warning: Trying to access array offset on value of type int in /in/KLaZr on line 33 Ocean wins! ---------- Comparing Orchid and Ya... 8600 VS 6950 Orchid wins! ---------- Warning: Trying to access array offset on value of type int in /in/KLaZr on line 22 Comparing Orchid and ... Warning: Trying to access array offset on value of type int in /in/KLaZr on line 24 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 28 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 32 -10000 VS Warning: Trying to access array offset on value of type int in /in/KLaZr on line 33 Orchid wins! ---------- Warning: Trying to access array offset on value of type int in /in/KLaZr on line 22 Comparing Ya and ... Warning: Trying to access array offset on value of type int in /in/KLaZr on line 24 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 28 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 32 -11650 VS Warning: Trying to access array offset on value of type int in /in/KLaZr on line 33 Ya wins! ---------- Warning: Trying to access array offset on value of type int in /in/KLaZr on line 46 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 46 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 46 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 46 ---------- Top: Warning: Trying to access array offset on value of type int in /in/KLaZr on line 53 Warning: Trying to access array offset on value of type int in /in/KLaZr on line 53 : Cala: 1 Ya: 2 Ocean: 3 Orchid: 4 ---------- Finalists: Warning: Trying to access array offset on value of type int in /in/KLaZr on line 60 Cala
Output for 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Comparing Cala and Ocean... 5000 VS 6150 Ocean wins! Notice: Undefined offset: 4 in /in/KLaZr on line 38 ---------- Comparing Cala and Orchid... 4600 VS 7200 Orchid wins! Notice: Undefined offset: 4 in /in/KLaZr on line 38 ---------- Comparing Cala and Ya... 6000 VS 6950 Ya wins! Notice: Undefined offset: 4 in /in/KLaZr on line 38 ---------- Notice: Trying to access array offset on value of type int in /in/KLaZr on line 22 Comparing Cala and ... Notice: Trying to access array offset on value of type int in /in/KLaZr on line 24 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 28 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 32 -12600 VS Notice: Trying to access array offset on value of type int in /in/KLaZr on line 33 Cala wins! Notice: Undefined offset: 4 in /in/KLaZr on line 35 ---------- Comparing Ocean and Orchid... 5750 VS 7200 Orchid wins! ---------- Comparing Ocean and Ya... 7150 VS 6950 Ocean wins! ---------- Notice: Trying to access array offset on value of type int in /in/KLaZr on line 22 Comparing Ocean and ... Notice: Trying to access array offset on value of type int in /in/KLaZr on line 24 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 28 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 32 -11450 VS Notice: Trying to access array offset on value of type int in /in/KLaZr on line 33 Ocean wins! ---------- Comparing Orchid and Ya... 8600 VS 6950 Orchid wins! ---------- Notice: Trying to access array offset on value of type int in /in/KLaZr on line 22 Comparing Orchid and ... Notice: Trying to access array offset on value of type int in /in/KLaZr on line 24 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 28 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 32 -10000 VS Notice: Trying to access array offset on value of type int in /in/KLaZr on line 33 Orchid wins! ---------- Notice: Trying to access array offset on value of type int in /in/KLaZr on line 22 Comparing Ya and ... Notice: Trying to access array offset on value of type int in /in/KLaZr on line 24 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 28 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 32 -11650 VS Notice: Trying to access array offset on value of type int in /in/KLaZr on line 33 Ya wins! ---------- Notice: Trying to access array offset on value of type int in /in/KLaZr on line 46 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 46 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 46 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 46 ---------- Top: Notice: Trying to access array offset on value of type int in /in/KLaZr on line 53 Notice: Trying to access array offset on value of type int in /in/KLaZr on line 53 : Cala: 1 Ya: 2 Ocean: 3 Orchid: 4 ---------- Finalists: Notice: Trying to access array offset on value of type int in /in/KLaZr on line 60 Cala
Output for 7.3.32 - 7.3.33, 7.4.26
Comparing Cala and Ocean... 5000 VS 6150 Ocean wins! ---------- Comparing Cala and Orchid... 4600 VS 7200 Orchid wins! ---------- Comparing Cala and Ya... 6000 VS 6950 Ya wins! ---------- Comparing Cala and ... -12600 VS Cala wins! ---------- Comparing Ocean and Orchid... 5750 VS 7200 Orchid wins! ---------- Comparing Ocean and Ya... 7150 VS 6950 Ocean wins! ---------- Comparing Ocean and ... -11450 VS Ocean wins! ---------- Comparing Orchid and Ya... 8600 VS 6950 Orchid wins! ---------- Comparing Orchid and ... -10000 VS Orchid wins! ---------- Comparing Ya and ... -11650 VS Ya wins! ---------- ---------- Top: : Cala: 1 Ya: 2 Ocean: 3 Orchid: 4 ---------- Finalists: Cala
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
Comparing Cala and Ocean... 5000 VS 6150 Ocean wins! Notice: Undefined offset: 4 in /in/KLaZr on line 38 ---------- Comparing Cala and Orchid... 4600 VS 7200 Orchid wins! Notice: Undefined offset: 4 in /in/KLaZr on line 38 ---------- Comparing Cala and Ya... 6000 VS 6950 Ya wins! Notice: Undefined offset: 4 in /in/KLaZr on line 38 ---------- Comparing Cala and ... -12600 VS Cala wins! Notice: Undefined offset: 4 in /in/KLaZr on line 35 ---------- Comparing Ocean and Orchid... 5750 VS 7200 Orchid wins! ---------- Comparing Ocean and Ya... 7150 VS 6950 Ocean wins! ---------- Comparing Ocean and ... -11450 VS Ocean wins! ---------- Comparing Orchid and Ya... 8600 VS 6950 Orchid wins! ---------- Comparing Orchid and ... -10000 VS Orchid wins! ---------- Comparing Ya and ... -11650 VS Ya wins! ---------- ---------- Top: : Cala: 1 Ya: 2 Ocean: 3 Orchid: 4 ---------- Finalists: Cala
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/KLaZr on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/KLaZr on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/KLaZr on line 3
Process exited with code 255.

preferences:
329 ms | 401 KiB | 452 Q