3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.1.0 - 7.1.23, 7.2.0 - 7.2.11
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.

preferences:
177.83 ms | 1394 KiB | 44 Q