2013-08-17 109 views
0

我有一個包含許多其他數組的數組。第一項是base64編碼的字符串,第二項是真正的字符串。數組內部的數組 - 按字母順序排序

如何根據第二個字符串按字母順序對數組進行排序?

Array 
(
    [3] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDE0IC0gbGEgcmV2YW5jaGUgZGVzIHZhaW5jdXMgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => kochise - 14 - la revanche des vaincus [www.pirate-punk.net].mp3 

     ) 

    [9] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDE1IC0gbGUgY29tcHRlIGQnIGF1am91ZCdodWkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => kochise - 15 - le compte d' aujoud'hui [www.pirate-punk.net].mp3 

     ) 

    [18] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDE2IC0gc2OKbmUgZGUgcmFjaXNtZSBvcmRpbmFpcmUgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => kochise - 16 - sc�ne de racisme ordinaire [www.pirate-punk.net].mp3 

     ) 

    [16] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDE3IC0gY2hhbnNvbiBwb3VyIHBhbnR4b2EgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => kochise - 17 - chanson pour pantxoa [www.pirate-punk.net].mp3 

     ) 

    [13] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDE4IC0gZi5sLmEgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => kochise - 18 - f.l.a [www.pirate-punk.net].mp3 

     ) 

    [15] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDE5IC0gdGVycmUgYnJ1bIJlcyAgW3d3dy5waXJhdGUtcHVuay5uZXRdLm1wMwo= 
      [1] => kochise - 19 - terre brul�es [www.pirate-punk.net].mp3 

     ) 

    [8] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDExIC0gdGVycmUgdmlvbIJlICBbd3d3LnBpcmF0ZS1wdW5rLm5ldF0ubXAzCg== 
      [1] => kochise - 11 - terre viol�e [www.pirate-punk.net].mp3 

     ) 

    [19] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDEyIC0gbGVzIHRlbXBzIG1vZGVybmVzICBbd3d3LnBpcmF0ZS1wdW5rLm5ldF0ubXAzCg== 
      [1] => kochise - 12 - les temps modernes [www.pirate-punk.net].mp3 

     ) 

    [4] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDEzIC0gMSAtIGZlbW1lIHN1ciAyIC0gZXN0IDEgaG9tbWUgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => kochise - 13 - 1 - femme sur 2 - est 1 homme [www.pirate-punk.net].mp3 

     ) 

    [7] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDIwIC0gZGFtZSBkeW5hbWl0ZSAgW3d3dy5waXJhdGUtcHVuay5uZXRdLm1wMwo= 
      [1] => kochise - 20 - dame dynamite [www.pirate-punk.net].mp3 

     ) 

    [2] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDA0IC0gcm9jayB0ZXJyb3Jpc3RlICBbd3d3LnBpcmF0ZS1wdW5rLm5ldF0ubXAzCg== 
      [1] => haine brigade - 04 - rock terroriste [www.pirate-punk.net].mp3 

     ) 

    [12] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDA1IC0gY2lhIGdvbmUgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => haine brigade - 05 - cia gone [www.pirate-punk.net].mp3 

     ) 

    [14] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDA2IC0gZGVtYWluIHNlcmEgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => haine brigade - 06 - demain sera [www.pirate-punk.net].mp3 

     ) 

    [5] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDA3IC0gcGFzc2FnZXIgY2xhbmRlc3RpbiAgW3d3dy5waXJhdGUtcHVuay5uZXRdLm1wMwo= 
      [1] => haine brigade - 07 - passager clandestin [www.pirate-punk.net].mp3 

     ) 

    [17] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDA4IC0gaSBnb25uYSBkbyBteSBoZWFkICBbd3d3LnBpcmF0ZS1wdW5rLm5ldF0ubXAzCg== 
      [1] => haine brigade - 08 - i gonna do my head [www.pirate-punk.net].mp3 

     ) 

    [0] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDA5IC0gbnJ2ICBbd3d3LnBpcmF0ZS1wdW5rLm5ldF0ubXAzCg== 
      [1] => haine brigade - 09 - nrv [www.pirate-punk.net].mp3 

     ) 

    [10] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDAxIC0gY29tbWlzc2FyaWF0IGJsdWVzICBbd3d3LnBpcmF0ZS1wdW5rLm5ldF0ubXAzCg== 
      [1] => haine brigade - 01 - commissariat blues [www.pirate-punk.net].mp3 

     ) 

    [11] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDAyIC0gbWF0aGlsZGEgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => haine brigade - 02 - mathilda [www.pirate-punk.net].mp3 

     ) 

    [6] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDAzIC0gcGxlaW5lIGx1bmUgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => haine brigade - 03 - pleine lune [www.pirate-punk.net].mp3 

     ) 

    [1] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAjaGFpbmUgYnJpZ2FkZSAtIDEwIC0gZmFjZSCFIGZhY2UgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => haine brigade - 10 - face � face [www.pirate-punk.net].mp3 

     ) 

) 

這個例子,我需要與子陣基礎上通過「kochise」或「艾訥旅」

+1

你嘗試過什麼到目前爲止? –

+0

你看過usort嗎? http://us3.php.net/manual/en/function.usort.php – 2013-08-17 21:10:42

回答

3

這裏:

function cmp($a, $b) 
{ 
    return strcmp($a[1], $b[1]); 
} 

usort($your_data, "cmp"); 
0
function aasort(&$yourarrayname, $key) { //this function will do this for you, just input the 

//array name and the key name for this target array for the association 
     $sorter=array(); //here we initialize the arrays to order or sort as you like 
     $ret=array(); 
     reset($yourarrayname); //good code practices 
     foreach ($array as $ii => $va) {  //loop through the array and sort each to each in this //new arrays 
      $sorter[$ii]=$va[$key]; //storing 
     } 
     asort($sorter, SORT_NATURAL | SORT_FLAG_CASE); //assort as alphabetic 
     foreach ($sorter as $ii => $va) { 
      $ret[$ii]=$array[$ii]; 
     } 
     $array=$ret; 
    } 
     //call it like this 
    aasort($your_array,"key"); 
+0

注意:Undefined variable:數組在/var/www/clients/client2/web1/web/playlist.php上線171/ 警告:在/ var/www/clients/client2中使用未定義的常量SORT_NATURAL - 假定爲'SORT_NATURAL',使用/var/www/clients/client2/web1/web/playlist.php中的foreach()提供的無效參數171/ /web1/web/playlist.php 174行/注意:使用未定義的常量SORT_FLAG_CASE - 假設'SORT_FLAG_CASE'在/var/www/clients/client2/web1/web/playlist.php上174行/警告:asort()希望參數2很長,字符串在/var/www/clients/client2/web1/web/playlist.php中給出 – libertaire

+0

@libertaire如果你沒有發現問題,我們可以去聊天我知道你爲什麼有這個問題,但我需要看看你是如何填充數組。你能上傳創建數組的代碼嗎? –

-3

來解決這個問題簡單的方法啓動字符串按字母順序排序是創建像這樣的數組: 這樣做可以讓你使用PHP排序功能。

Array 
(
    ["kochise - 14 - la revanche des vaincus [www.pirate-punk.net].mp3"] => Array 
     (
      [0] => ZGwvcHAvNjI1MC9rb2NoaXNlICsgaGFpbmUgYnJpZ2FkZSAtIHNhdXZhZ2VzIChzcGxpdCkgIFt3d3cucGlyYXRlLXB1bmsubmV0XS56aXAja29jaGlzZSAtIDE0IC0gbGEgcmV2YW5jaGUgZGVzIHZhaW5jdXMgIFt3d3cucGlyYXRlLXB1bmsubmV0XS5tcDMK 
      [1] => kochise - 14 - la revanche des vaincus [www.pirate-punk.net].mp3 
1
function cmp($a, $b) { 

    return strcmp($a[1], $b[1]); 
} 

usort($myArray, 'cmp');