1

ご覧のとおり、2次元配列は次のとおりです。

Array ( [0] => Array ( [0] => Prishtina [1] => Bregu i Diellit [2] => 7 ) 
    [1] => Array ( [0] => Prishtina [1] => Tasligje [2] => 4 ) 
    [2] => Array ( [0] => Prishtina [1] => Bregu i Diellit [2] => 4 ) 
    [3] => Array ( [0] => Prishtina [1] => Bregu i Diellit [2] => 3 ) 
    [4] => Array ( [0] => Prishtina [1] => Bregu i Diellit [2] => 9 ) 
    [5] => Array ( [0] => Prishtina [1] => Lakrishte [2] => 4 ) 
    [6] => Array ( [0] => Prishtina [1] => Lakrishte [2] => 6 ) 
    [7] => Array ( [0] => Prishtina [1] => Lakrishte [2] => 1 ) 
    [8] => Array ( [0] => Prishtina [1] => Ulpiana [2] => 3 ) 
    [9] => Array ( [0] => Prishtina [1] => Ulpiana [2] => 6 ) 
    [10] => Array ( [0] => Prishtina [1] => Ulpiana [2] => 5 ) 
    [11] => Array ( [0] => Prishtina [1] => Ulpiana [2] => 8 ) 
    [12] => Array ( [0] => Prishtina [1] => Ulpiana [2] => 4 ) 
    [13] => Array ( [0] => Prishtina [1] => Ulpiana [2] => 8 ) 
    [14] => Array ( [0] => Prishtina [1] => Velania [2] => 2 ) 
    [15] => Array ( [0] => Prishtina [1] => Velania [2] => 5 ) 
    [16] => Array ( [0] => Prishtina [1] => Velania [2] => 1 ) 
    [17] => Array ( [0] => Prishtina [1] => Dragodan [2] => 9 ) 
    [18] => Array ( [0] => Prishtina [1] => Dragodan [2] => 7 ) 
    [19] => Array ( [0] => Prishtina [1] => Dragodan [2] => 10 ) 
    [20] => Array ( [0] => Prishtina [1] => Velania [2] => 11 ) 
    [21] => Array ( [0] => Mitrovica [1] => Qender [2] => 5 ) 
    [22] => Array ( [0] => Mitrovica [1] => Qender [2] => 3 ) 
    [23] => Array ( [0] => Mitrovica [1] => Tavnik [2] => 6 ) 
    [24] => Array ( [0] => Mitrovica [1] => Tavnik [2] => 9 ) 
    [25] => Array ( [0] => Mitrovica [1] => Bair [2] => 10 ) 
    [26] => Array ( [0] => Mitrovica [1] => Bair [2] => 12 ) 
    [27] => Array ( [0] => ) ) 

次のコードを使用して、3 番目の列で並べ替えようとしています。

foreach ($final_array as $roww){
    $sort_column[]= $roww[2];   // 2 = your example
    array_multisort($sort_column, $final_array);
}

ただし、印刷する場合:

for ($row = 0; $row < count($final_array); $row++)
{
    foreach($final_array[$row] as $key => $value)
        {
            echo $value;
        }
        echo "<br/>";
 }

私が印刷しているとき、それは並べ替えられ、3番目の列で並べ替えられた配列を印刷しますが、これらの警告が表示されます

Warning: array_multisort() [function.array-multisort]: Array sizes are inconsistent in   C:\xampp\htdocs\test\test.php on line 35
 Notice: Undefined offset: 2 in C:\xampp\htdocs\test\test.php on line 34

なぜこれが起こっているのかわかりません。私には意味がありません。すべてが機能していますが、これらの警告が必要です!!

4

3 に答える 3

0

array_multisort() を使用して一度に多くの配列をソートすると、マルチソートを実行するために選択されたすべての配列のサイズが異なる場合、警告が表示されます。

$arr = array(
    'UK' => array(
        'John' => 'Toyota',
        'Alice' => 'Opel',
        'Evan' => 'Fiat',
        'Gregory' => 'Mitsubishi'
    ),
    'Germany' => array(
        'Bruno' => 'Opel',
        'Andreas' => 'Mercedes',
        'Klaus' => 'Porsche',
    )
);

見る?両方の配列の要素数が異なります。したがって、array_multisort は、オプションが異なっていても、これらの配列を同じ方法でソートしようとします。

array_multisort(
    $arr['Germany'], SORT_ASC, SORT_NATURAL,
    $arr['UK'], SORT_DESC, SORT_NUMERIC
    );

これにより、次のような警告が出力されます: 警告: array_multisort(): 配列サイズは (...) で矛盾しています

于 2014-04-08T08:42:47.957 に答える