我想我的排序数组,我不断收到的1PHP排序assocative
这里结果是代码的请求帮助
$foo = array(
2 => "Sports",
40 => "Parent and Families",
43 => "Arts and Entertainment",
);
$foo = sort($foo);
我希望他们通过价值
排序我想我的排序数组,我不断收到的1PHP排序assocative
这里结果是代码的请求帮助
$foo = array(
2 => "Sports",
40 => "Parent and Families",
43 => "Arts and Entertainment",
);
$foo = sort($foo);
我希望他们通过价值
排序Sort不返回排序的数组。它在成功时返回FALSE的TRUE。该数组通过引用传递。所以调用该方法,只是用它
$foo = array(
2 => "Sports",
40 => "Parent and Families",
43 => "Arts and Entertainment",
);
sort($foo); //foo is now sorted
编辑
不过请注意,那种()实际上重新分配你的指数。您应该使用asort()
而不是那种,如果你想保持协会
可以使用asort()
如果需要mainatin指数的关联,使用asort(array &$array [, int $sort_flags = SORT_REGULAR])。请注意$ array上的引用传递( - >检查手册是什么函数输出)。
$foo = array(
2 => "Sports",
40 => "Parent and Families",
43 => "Arts and Entertainment",
);
asort($foo);
print_r($foo);
打印
Array
(
[43] => Arts and Entertainment
[40] => Parent and Families
[2] => Sports
)
谢谢!让我疯狂 – mcgrailm 2011-02-25 20:01:05
我认为你的意思是asort()(arsort是一个与索引关联的反向排序)。 – Czechnology 2011-02-25 20:02:54
@Czechnology烨,我的意思是asort。我输入了arsort()吗?道歉,饮料和深夜不好与良好的答案:S 感谢您编辑@Gaurav – JohnP 2011-02-25 20:06:15