I have a two dimensional array that I need to sort based on a total of values in the second dimension. The top level array has a part number and another array as its elements. The second array consists of defect types and defect quantity corresponding to the part number.
I am able to sort the second defect array by defect type (so whichever type has the highest quantity shows up first) but I am not sure how to sort so that the parts with the highest total defects are first. Essentially I need to sort based on the total quantities in the second array, but I am not sure how to do that on the fly. Here is a print_r of the array
Part#101 Array ( [Scratches] => 6 )
Part#102 Array ( [Scratches] => 174 [Handling] => 22 [Supplier Mold Defect] => 9 [Dirt] => 9 )
Part#103 Array ( [Scratches] => 167 [Dirt] => 116 [Handling] => 4 [Water Spots] => 3 [Supplier Mold Defect] => 1 )
Part#104 Array ( [Scratches] => 20 [Supplier Mold Defect] => 4 )
After sorting the part order should be:
Part#103 (291 total defects)
Part#102 (214 total defects)
Part#104 (24 total defects)
Part#101 (6 total defects)