魏长东

weichangdong

php array_multisort

<?php
$uploaded_img_files=[];
$uploaded_img_files[] = [
                            'full_name' => '3.jpg',
                            'extension' => 'jpg',
                            'file_name' => '3',
                            ];
$uploaded_img_files[] = [
                            'full_name' => '1.jpg',
                            'extension' => 'jpg',
                            'file_name' => '1',
                            ];
$uploaded_img_files[] = [
                            'full_name' => '2.jpg',
                            'extension' => 'jpg',
                            'file_name' => '2',
                            ];
                            
        
        $uploaded_img_files[] = [
                            'full_name' => '7.jpg',
                            'extension' => 'jpg',
                            'file_name' => '7',
                            ];   



//array_multisort ( $uploaded_img_files [ "file_name" ],  SORT_NUMERIC ,  SORT_DESC );


          foreach ($uploaded_img_files as $key => $v) {
            $need_sort[$key] = $v['file_name'];
          }          
          array_multisort ( $need_sort , SORT_NUMERIC, SORT_ASC , $uploaded_img_files );     
             
                          //  print_r($uploaded_img_files);
                 
$str = 'http://sanguofengyun.i.wcd.com/sticker/6_149742815654.png,
http://sanguofengyun.i.wcd.com/sticker/5_149742815683.png,
http://sanguofengyun.i.wcd.com/sticker/4_149742815730.png,
http://sanguofengyun.i.wcd.com/sticker/3_149742815853.png,
http://sanguofengyun.i.wcd.com/sticker/2_149742815889.png,
http://sanguofengyun.i.wcd.com/sticker/1_149742815996.png';
          
          $wcd = explode(',',$str);
          $need_sort=[];
     foreach ($wcd as $key => $v) {
        $tmp = explode('/',$v);
        $tmp = array_pop($tmp);
        $seq_name = explode('_',$tmp)[0];
        
            $need_sort[$key] = $seq_name;
          }          
          array_multisort ( $need_sort , SORT_NUMERIC, SORT_ASC , $wcd ); 
          print_r($wcd);