【发布时间】:2012-02-05 06:05:26
【问题描述】:
我想比较从数组 [0] 到数组末尾的距离,并用它的键显示最短距离。
数组 ( [0] => 数组 ( [城市] => 数组 ( [0] => 减少 [1] => 仙人掌 )
[distance] => 14.4
)
[1] => Array
(
[city] => Array
(
[0] => Array
(
[0] => Reduit
[1] => Ebe
)
[1] => Bees Village
[2] => Phoen Trunk Rd
[3] => Riv,Phoenix
[4] => St l Rd
[5] => Geoes Guibert St
[6] => Curepipe
)
[distance] => 1.4
)
[2] => Array
(
[city] => Array
(
[0] => Array
(
[0] => Reduit
[1] => Riv,Phoenix
)
[1] => St l Rd
[2] => Geoes Guibert St
[3] => Curepipe
)
[distance] => 3.4
)
[3] => Array
(
[city] => Array
(
[0] => Array
(
[0] => Reduit
[1] => Ebene
)
[1] => Belles Village
[2] => Phoenix Trunk Rd
[3] => Riverside,Phoenix
[4] => St Paul Rd
[5] => Georges Guibert St
[6] => Curepipe
)
[distance] => 22.4
)
)
我用过,
$total = count($array)-1; $current = $array[0]['距离'];
for($loop=1;$loop<$total;$loop++){
$next = $array[$loop]['distance'];
$current = $next;
$current = $current;
if ($next>$current){
print_r($current);
}
}
}
要获取所有键的索引,请获取第一个索引并使用交换将其与其他值进行比较.. 但它不起作用。有人有修复请。谢谢你
【问题讨论】: