3v4l.org

run code in 300+ PHP versions simultaneously
<?php $original = array(12, 17, 5, 27, 5); // strip duplicates as they are ranked equally $rankings = array_unique($original); // apply some sorting so that the ranks are now given by the keys. rsort($rankings); // now just use the origincal array and lookup the rankings for each value $return = array(); foreach($original as $value) { $rankedValue = array(); $rankedValue['value'] = $value; $rankedValue['rank'] = array_search($value, $rankings) + 1; $return[] = $rankedValue; } var_dump($return);
Output for git.master, git.master_jit, rfc.property-hooks
array(5) { [0]=> array(2) { ["value"]=> int(12) ["rank"]=> int(3) } [1]=> array(2) { ["value"]=> int(17) ["rank"]=> int(2) } [2]=> array(2) { ["value"]=> int(5) ["rank"]=> int(4) } [3]=> array(2) { ["value"]=> int(27) ["rank"]=> int(1) } [4]=> array(2) { ["value"]=> int(5) ["rank"]=> int(4) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
44.68 ms | 402 KiB | 8 Q