3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $values = array(); $values[0] = 5; $values[1] = 12; $values[2] = 19; $values[3] = 9; $ordered_values = $values; rsort($ordered_values); foreach ($values as $key => $value) { foreach ($ordered_values as $ordered_key => $ordered_value) { if ($value === $ordered_value) { $key = $ordered_key; break; } } echo $value . "- Rank: " . ((int) $key + 1) . "\n"; }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
5- Rank: 4 12- Rank: 2 19- Rank: 1 9- Rank: 3