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) . '<br/>'; }
Output for 4.3.0 - 7.1.0
5- Rank: 4<br/>12- Rank: 2<br/>19- Rank: 1<br/>9- Rank: 3<br/>