Home > Backend Development > PHP Tutorial > php二维数组排序解决思路

php二维数组排序解决思路

WBOY
Release: 2016-06-13 12:11:27
Original
817 people have browsed it

php二维数组排序
$arr = array (
  array ('desc' => 'pic13.jpg'),
  array ('desc' => 'pic18.jpg'),
  array ('desc' => 'pic21.jpg'),
  array ('desc' => 'pic22.jpg'),
  array ('desc' => 'pic23.jpg'),
  array ('desc' => 'pic5.jpg'),
  array ('desc' => 'pic6.jpg'),
  array ('desc' => 'pic7.jpg'),
  array ('desc' => 'pic8.jpg'),
  array ('desc' => 'pic9.jpg'),
);

数组的desc按照顺序排列,值按照从小到大。
------解决思路----------------------

$arr = array (<br />  array ('desc' => 'pic13.jpg'),<br />  array ('desc' => 'pic18.jpg'),<br />  array ('desc' => 'pic21.jpg'),<br />  array ('desc' => 'pic22.jpg'),<br />  array ('desc' => 'pic23.jpg'),<br />  array ('desc' => 'pic5.jpg'),<br />  array ('desc' => 'pic6.jpg'),<br />  array ('desc' => 'pic7.jpg'),<br />  array ('desc' => 'pic8.jpg'),<br />  array ('desc' => 'pic9.jpg'),<br />);<br />foreach($arr as $v) $r[] = substr($v['desc'], 3, -4);<br />array_multisort($r, $arr);<br />print_r($arr);
Copy after login
Array
(
    [0] => Array
        (
            [desc] => pic5.jpg
        )

    [1] => Array
        (
            [desc] => pic6.jpg
        )

    [2] => Array
        (
            [desc] => pic7.jpg
        )

    [3] => Array
        (
            [desc] => pic8.jpg
        )

    [4] => Array
        (
            [desc] => pic9.jpg
        )

    [5] => Array
        (
            [desc] => pic13.jpg
        )

    [6] => Array
        (
            [desc] => pic18.jpg
        )

    [7] => Array
        (
            [desc] => pic21.jpg
        )

    [8] => Array
        (
            [desc] => pic22.jpg
        )

    [9] => Array
        (
            [desc] => pic23.jpg
        )

)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template