的項目我與這些得分值的數組:PHP分配分數陣列
$r = Array
(
[C] => 11.00.00
[B] => 11.00.00
[G] => 11.00.00
[F] => 10.02.00
[A] => 10.00.00
[D] => 09.00.00
[E] => 08.00.00
[H] => 08.00.00
[I] => 07.00.00
[K] => 06.00.00
[J] => 06.00.00
)
我需要指定一個數字的位置,但是,同樣的分數將具有相同的位置,例如:
A : 1 -- draw score
B : 1 -- draw score
C : 1 -- draw score
D : 4 -- not 2, because the previous position
E : 5 -- normal
F : 6 -- normal
G : 7 -- draw score
H : 7 -- draw score
I : 9 -- not 8, because the previous position
...
我已經試過分數組項目,並與編號開始:
組
$result = array();
foreach($r as $k => $v)
{
$result[$k] = array_keys($r, $r[$k]);
}
編號
$p = $c = 1;
foreach($result as $k => $v)
{
$ac = count($v);
if($ac==1)
{
$p = $p+$c;
$c = 1;
}
else
{
$c = $ac;
}
$result[$k] = $p;
}
print_r($result);
,但我有這樣的:
Array
(
[C] => 1
[B] => 1
[G] => 1
[F] => 4
[A] => 5
[D] => 6
[E] => 6
[H] => 6
[I] => 8
[K] => 8
[J] => 8
)
我需要:
Array
(
[C] => 1
[B] => 1
[G] => 1
[F] => 4
[A] => 5
[D] => 6
[E] => 7
[H] => 7
[I] => 9
[K] => 10
[J] => 10
)
我怎樣才能正確排序?
我做了它,但我不得不使用3的foreach .. 。投票或你的答案,因爲它是最優化的。謝謝! – csotelo