热搜:NVER node 开发 php

php二维数组排序

2024-08-15 21:15:01
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 (  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'),);foreach($arr as $v) $r[] = substr($v['desc'], 3, -4);array_multisort($r, $arr);print_r($arr);
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
)

)

PHP code?123456789101112131415$arr = array ( array ('desc' => 'pic13.jpg'), array ('desc' => 'pic18.jpg'), array ('desc' => 'pic21.jpg'), array ('desc' => 'pic22.jpg'), array ('desc'……

array (  0 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130219/20130219100027_73278.jpg',    'desc' => 'pic13.jpg',    'dl_url' => NULL,  ),  1 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130219/20130219100027_13751.jpg',    'desc' => 'pic18.jpg',    'dl_url' => NULL,  ),  2 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130219/20130219100027_88544.jpg',    'desc' => 'pic21.jpg',    'dl_url' => NULL,  ),  3 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130219/20130219100027_81776.jpg',    'desc' => 'pic22.jpg',    'dl_url' => NULL,  ),  4 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130219/20130219100027_46419.jpg',    'desc' => 'pic23.jpg',    'dl_url' => NULL,  ),  5 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130109/20130109163252_56244.jpg',    'desc' => 'pic5.jpg',    'dl_url' => NULL,  ),  6 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130109/20130109163930_58718.jpg',    'desc' => 'pic6.jpg',    'dl_url' => NULL,  ),  7 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130110/20130110092551_30522.jpg',    'desc' => 'pic7.jpg',    'dl_url' => NULL,  ),  8 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130114/20130114115936_39995.jpg',    'desc' => 'pic8.jpg',    'dl_url' => NULL,  ),  9 =>   array (    'type' => '1',    'url' => '/erp/staticment/dynamic/../../data/images/upload/20130219/20130219100027_52973.jpg',    'desc' => 'pic9.jpg',    'dl_url' => NULL,  ),)
原始的二维数组是这样的,排序之后,还需要显示出来。

PHP code?123456789101112131415$arr = array (  array ('desc' => 'pic13.jpg'),  array ('desc' => 'pic18.jpg'),  array ('desc' => 'pic21.jpg'),  array ('desc' => 'pic22.jpg'),  array ('desc'……



原来截取的也算啊,看来php开发者对这个函数做了不少匹配啊

那不是一样吗?

那不是一样吗?

是我自身程序的原因,多谢老大~~~

不是有数组排序函数吗?