开发者

how can I sort an array in php?

开发者 https://www.devze.com 2023-01-04 09:03 出处:网络
Example : $a [] = array (\'google\',\'bing\',\'yahoo\'); $a [] = array (\'America\',\'F开发者_开发百科rance\',\'Germany\');

Example :

$a [] = array ('google','bing','yahoo');
$a [] = array ('America','F开发者_开发百科rance','Germany');
$a [] = array ('Africa','Asia','Europe');

And I want to sort her in table like that :

Africa....... America........ google.......


You can do sort($a).

This first Google result for "sort array php" is this:

http://php.net/manual/en/function.sort.php


You can use array_multisort, specially if your inner arrays has same size. I have checcked it, hope it will serve as you need.


  1. Why your array is multidimensional?
  2. Join your nested arrays into one, sort it, and then you can output that sorted array in a manner you wish


Try this:

$resort = "return (1*strnatcmp(\$x['0'], \$y['0']));";
uasort($a, create_function('$x,$y', $resort));
print_r($a);
0

精彩评论

暂无评论...
验证码 换一张
取 消