我已经从MySQL查询生成了一个数组,然后我使用subval_sort()重新排序。除了字母" E"订购中的数字。在这些情况下,使用" E"在它首先出来。我有四个这种情况发生,但在其他地方(这是一个非常大的网站,顺便说一句),订购工作正常。
这是我的数组,因为它是从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" ) )
有什么想法吗?提前致谢
答案 0 :(得分: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);