-1

MySQL クエリから配列を生成し、subval_sort() を使用して並べ替えました。これは、文字「E」が順序付けされている場合を除き、正常に機能します。その場合、「E」が入った値が最初に出てきます。私はこれが起こっている4つのインスタンスを持っていますが、他のどこでも(これは非常に大きなサイトです、ところで)注文はうまくいきます.

これは、db クエリから生成された配列です。

Array ( 
[] => Array ( [Item #] => 091055070 [Size Code] => 7 [D Diameter] => 5/8" [d Small Diameter (Pilot) ] => 1/4" [L Length] => 3 1/4" ) 
[1] => Array ( [Item #] => 091055060 [Size Code] => 6 [D Diameter] => 1/2" [d Small Diameter (Pilot) ] => 7/32" [L Length] => 3" ) 
[2] => Array ( [Item #] => 091055050 [Size Code] => 5 [D Diameter] => 7/16" [d Small Diameter (Pilot) ] => 3/16" [L Length] => 2 3/4" ) 
[3] => Array ( [Item #] => 091055040 [Size Code] => 4 [D Diameter] => 5/16" [d Small Diameter (Pilot) ] => 1/8" [L Length] => 2 1/8" ) 
[4] => Array ( [Item #] => 091055030 [Size Code] => 3 [D Diameter] => 1/4" [d Small Diameter (Pilot) ] => 7/64" [L Length] => 2" ) 
[5] => Array ( [Item #] => 091055020 [Size Code] => 2 [D Diameter] => 3/16" [d Small Diameter (Pilot) ] => 5/64" [L Length] => 1 7/8" ) 
[6] => Array ( [Item #] => 091055010 [Size Code] => 1 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => 3/64" [L Length] => 1 1/4" ) 
[7] => Array ( [Item #] => 0910550E0 [Size Code] => 0 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => 1/32" [L Length] => 1 1/4" ) 
[8] => Array ( [Item #] => 091055080 [Size Code] => 8 [D Diameter] => 3/4" [d Small Diameter (Pilot) ] => 5/16" [L Length] => 3 1/2" ) 
[9] => Array ( [Item #] => 0910550D0 [Size Code] => 00 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => .025" [L Length] => 1 1/4" ) 
[10] => Array ( [Item #] => 0910550C0 [Size Code] => 000 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => .020" [L Length] => 1 1/4" ) 
[11] => Array ( [Item #] => 0910550B0 [Size Code] => 0000 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => .015" [L Length] => 1 1/4" ) 
[12] => Array ( [Item #] => 0910550A0 [Size Code] => 00000 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => .010" [L Length] => 1 1/4" ) )

私はこの行を実行します:

$productArray = subval_sort($productArray,'Item #');

すると次のようになります。

Array ( 
[0] => Array ( [Item #] => 0910550E0 [Size Code] => 0 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => 1/32" [L Length] => 1 1/4" ) 
[1] => Array ( [Item #] => 091055010 [Size Code] => 1 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => 3/64" [L Length] => 1 1/4" ) 
[2] => Array ( [Item #] => 091055020 [Size Code] => 2 [D Diameter] => 3/16" [d Small Diameter (Pilot) ] => 5/64" [L Length] => 1 7/8" ) 
[3] => Array ( [Item #] => 091055030 [Size Code] => 3 [D Diameter] => 1/4" [d Small Diameter (Pilot) ] => 7/64" [L Length] => 2" ) 
[4] => Array ( [Item #] => 091055040 [Size Code] => 4 [D Diameter] => 5/16" [d Small Diameter (Pilot) ] => 1/8" [L Length] => 2 1/8" ) 
[5] => Array ( [Item #] => 091055050 [Size Code] => 5 [D Diameter] => 7/16" [d Small Diameter (Pilot) ] => 3/16" [L Length] => 2 3/4" ) 
[6] => Array ( [Item #] => 091055060 [Size Code] => 6 [D Diameter] => 1/2" [d Small Diameter (Pilot) ] => 7/32" [L Length] => 3" ) 
[7] => Array ( [Item #] => 091055070 [Size Code] => 7 [D Diameter] => 5/8" [d Small Diameter (Pilot) ] => 1/4" [L Length] => 3 1/4" ) 
[8] => Array ( [Item #] => 091055080 [Size Code] => 8 [D Diameter] => 3/4" [d Small Diameter (Pilot) ] => 5/16" [L Length] => 3 1/2" ) 
[9] => Array ( [Item #] => 0910550A0 [Size Code] => 00000 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => .010" [L Length] => 1 1/4" ) 
[10] => Array ( [Item #] => 0910550B0 [Size Code] => 0000 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => .015" [L Length] => 1 1/4" ) 
[11] => Array ( [Item #] => 0910550C0 [Size Code] => 000 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => .020" [L Length] => 1 1/4" ) 
[12] => Array ( [Item #] => 0910550D0 [Size Code] => 00 [D Diameter] => 1/8" [d Small Diameter (Pilot) ] => .025" [L Length] => 1 1/4" ) )

何か案は?前もって感謝します

4

1 に答える 1

1

おそらく、firsttube.com からの関数のこの変更は機能するはずです。

function subval_sort($a,$subkey,$sort_type="str") {
    foreach($a as $k=>$v) {
                if($sort_type == "hex") {
                    $b[$k] = hexdec($v[$subkey]);
                } else {
                    $b[$k] = strtolower($v[$subkey]);
                }
    }
    asort($b);
    foreach($b as $key=>$val) {
        $c[] = $a[$key];
    }
    return $c;
}


print_r($arr);
echo "<hr>";

$arr2 = subval_sort($arr, "Item #","hex");
print_r($arr2);
于 2013-09-24T05:31:47.637 に答える