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”或“haine brigade”开头的字符串按字母顺序对子数组进行排序

4

4 回答 4

3

这里:

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

usort($your_data, "cmp");
于 2013-08-17T21:17:06.047 回答
1
function cmp($a, $b) {

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

usort($myArray, 'cmp');
于 2013-08-17T21:22:01.033 回答
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");
于 2013-08-17T21:14:00.220 回答
-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
于 2013-08-17T21:15:04.170 回答