;\" c \",\" score \" = >;90),1= >array(\" name \" = >;\" a \",\" score \" = & gt80),2 = & gtarray(\" " />
$green = array(
0 = & gtarray(" name " = >;" c "," score " = >;90),
1= >array(" name " = >;" a "," score " = & gt80),
2 = & gtarray(" name " = >;" d "," score " = & gt80),
3 = & gtarray(" name " = >;" b "," score " = >;70),
4 = & gtarray(" name " = >;" e "," score " = >;60),
);
//排名1 2 2 4 5
//名稱C A D B E
//成績90 80 80 70 60
foreach($ green as $ k = & gt;$v){
if ($k == 0){
$ green[$ k][' site ']= 1;
}否則{
$ lk = $ k-1;
if ($green[$k]['score']!= $green[$lk]['score']){
$ NK = $ k+1;
$ green[$ k][' site ']= $ NK;
}否則{
$ green[$ k][' site ']= $ k;
}
}
}
這是結果
數組(5) {
[0]= >
數組(3) {
[" name "]= & gt;字符串(1) "c "
[" score "]= & gt;int(90)
[" site "]= & gt;int(1)
}
[1]= >
數組(3) {
[" name "]= & gt;字符串(1) "a "
[" score "]= & gt;int(80)
[" site "]= & gt;int(2)
}
[2]= >
數組(3) {
[" name "]= & gt;字符串(1) "d "
[" score "]= & gt;int(80)
[" site "]= & gt;int(2)
}
[3]= >
數組(3) {
[" name "]= & gt;字符串(1) "b "
[" score "]= & gt;int(70)
[" site "]= & gt;int(4)
}
[4]= >
數組(3) {
[" name "]= & gt;字符串(1) "e "
[" score "]= & gt;int(60)
[" site "]= & gt;int(5)
}
}