[英]how can I sort an array in php?
Example : 范例:
$a [] = array ('google','bing','yahoo');
$a [] = array ('America','France','Germany');
$a [] = array ('Africa','Asia','Europe');
And I want to sort her in table like that : 我想像这样在表中对她进行排序:
Africa....... America........ google....... 非洲.......美国........谷歌.......
You can do sort($a)
. 您可以执行
sort($a)
。
This first Google result for "sort array php" is this: 这是“ sort array php”的第一个Google搜索结果:
http://php.net/manual/en/function.sort.php http://php.net/manual/en/function.sort.php
You can use array_multisort , specially if your inner arrays has same size. 您可以使用array_multisort ,特别是如果内部数组的大小相同。 I have checcked it, hope it will serve as you need.
我已选中它,希望它能按您的需要使用。
Try this: 尝试这个:
$resort = "return (1*strnatcmp(\$x['0'], \$y['0']));";
uasort($a, create_function('$x,$y', $resort));
print_r($a);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.