3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $data = array('sam'=>40, 'james'=>41, 'sunday'=>39, 'jude'=>45); arsort($data);] sort('sam'); $i = 0; $prev = ""; $j = 0; foreach($data as $key => $val){ // loop array if($val != $prev){ // if values are the same as previous $i++; // add one $i += $j; // add counter of same values $j=0; }else{ $j++; // this is if two values after eachother are the same (sam & james) } $new[$key] = $i; // create new array with name as key and rank as position $prev = $val; // overwrite previous value } var_dump($new);
based on HIWYE
Output for 7.0.28 - 7.3.0rc3
Parse error: syntax error, unexpected ']', expecting end of file in /in/1oc3n on line 3
Process exited with code 255.
Output for 5.6.38
Parse error: syntax error, unexpected ']' in /in/1oc3n on line 3
Process exited with code 255.