我有一個具有兩個特定鍵/值對的數組數組。我想要做的是獲得由qty
決定的前5個唯一cause
值。這意味着它將按照唯一的值將cause
鍵組合在一起,然後總計每個原因的qty
鍵,並返回每個原因的前5個原因和總數量。數組對象前5個唯一值
這是print_r(array_values($ array))打印出來的東西。
Array (
[0] => Array ([cause] => Other (please comment) [qty] => 0.417)
[1] => Array ([cause] => Chem Out FC-DryStrAddTow [qty] => 0.430)
[2] => Array ([cause] => Chem Out FC-DryStrAddTow [qty] => 0.430)
[3] => Array ([cause] => Chem Out FC-DryStrAddTow [qty] => 0.513)
[4] => Array ([cause] => Chem Out FC-DryStrAddTow [qty] => 0.513)
[5] => Array ([cause] => Chem Out FC-DryStrAddTow [qty] => 0.750)
[6] => Array ([cause] => Chem Out FC-DryStrAddTow [qty] => 0.750)
[7] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.816)
[8] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.816)
[9] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.828)
[10] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.828)
[11] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.681)
[12] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.681)
[13] => Array ([cause] => No Cause Selected [qty] => 0.918)
[14] => Array ([cause] => No Cause Selected [qty] => 0.918)
[15] => Array ([cause] => No Cause Selected [qty] => 0.926)
[16] => Array ([cause] => No Cause Selected [qty] => 0.937)
[17] => Array ([cause] => No Cause Selected [qty] => 0.809)
[18] => Array ([cause] => No Cause Selected [qty] => 0.809)
[19] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.891)
[20] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.891)
[21] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.884)
[22] => Array ([cause] => Slitter Cut/Saw-Poor Cut [qty] => 0.884))
非常感謝您的幫助。
請格式化該blob的輸出,它實際上是不可讀的。 –
這是一個數組與子數組,而不是對象 – JvdBerg
可能的重複:http://stackoverflow.com/questions/96759/how-do-i-sort-a-multidimensional-array-in-php – bbb