【发布时间】:2012-05-09 16:56:31
【问题描述】:
我正在尝试根据数值首先为特定字段 (OurPrice) 输出最低数字的排名。
var_dump结果
$myarray = array_filter($rankresult);
natsort($myarray);
array(6) {
["Comp7"]=> string(3) "189"
["OurPrice"]=> string(3) "189"
["Comp9"]=> string(6) "198.99"
["Comp6"]=> string(3) "208"
["Comp3"]=> string(6) "226.97"
["Comp4"]=> string(3) "274"
}
您会注意到计数中总共有 6 个,其中两个是相同的数字,因此它等于相同的排名(即 Comp7 和 OurPrice 都在 6 中排名第 1)。
期望的输出:
我们的价格排名 = 1 of 6
【问题讨论】:
-
我不知道从这里去哪里。难道没有办法获取“OurPrice”的Rank顺序吗?
-
@ToddN:输出应该如何,只是Our Price Rank = 1 of 6?
-
是的,所以基本上我会使用
echo "Our Price Rank" . $rank . " of " . $count";类似的东西。
标签: php arrays sorting ranking