Question : HOW TO SORT MULT-DIM ARRAY IN PHP

I have a multi-dimensional array in PHP and would like to sort a rate field by ascending order.
The structure of the array is in Code Attachment here.  The hierachy of this array is as follows:  PLATFORM can have many MANUFACTURER's that can have many MODEL's.
I am calculating effiency rating for each PLATFORM, MFG, and MODEL row by taking the number of incidents/inventory count to derive breakage ratio.
The RATES sub-array corresponds to rows in the other sub-arrays; ie for PLATFORM, MFG, and MODEL an efficiency rate is calculated.  So, if I sort the RATES descending, I'd want to do that only within the MFG/MODEL    I removed rows from attached output of arraybut left enough to show structure and content. Any ideas?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
Array
(
    [id] => Array
        (
            [0] => 0
            [1] => 1
            [2] => 2
            [3] => 3
            [4] => 3
            [5] => 3
            [6] => 2
            [7] => 3
            [8] => 3
            [9] => 3
            [39] => 2
            [40] => 3
            [41] => 2
            [42] => 3
            [43] => 3
         )

    [platform] => Array
        (
            [0] => ENTERPRISE WIDE
            [1] => SERVER
            [2] => SERVER
            [3] => SERVER
            [4] => SERVER
            [5] => SERVER
            [6] => SERVER
            [7] => SERVER
            [8] => SERVER
            [9] => SERVER
            [39] => SERVER
            [40] => SERVER
            [41] => SERVER
            [42] => SERVER
            [43] => SERVER
            [44] => SERVER
            
        )

    [mfg] => Array
        (
            [0] => 
            [1] => 
            [2] => FUJITSU
            [3] => FUJITSU
            [4] => FUJITSU
            [5] => FUJITSU
            [6] => IBM
            [7] => IBM
            [8] => IBM
            [9] => IBM
            [39] => OTHER
            [40] => OTHER
            [41] => SUN
            [42] => SUN
            [43] => SUN
            
        )

    [model] => Array
        (
            [0] => 
            [1] => 
            [2] => 
            [3] => 250
            [4] => 650
            [5] => 850
            [6] => 
            [7] => 7017-S80
            [8] => 7026-6H1
            [9] => 7026-6M1
            [39] => 
            [40] => K460
            [41] => 
            [42] => 1000E
            [43] => 12K
            
        )

    [count] => Array
        (
            [0] => 503
            [1] => 503
            [2] => 1
            [3] => 1
            [4] => 1
            [5] => 1
            [6] => 50
            [7] => 1
            [8] => 1
            [9] => 2
            [39] => 1
            [40] => 1
            [41] => 451
            [42] => 1
            [43] => 2
         )    

    [invcount] => Array
        (
            [0] => 21556
            [1] => 21556
            [2] => 57
            [3] => 13
            [4] => 10
            [5] => 26
            [6] => 1653
            [7] => 36
            [8] => 11
            [9] => 37
            [39] => 0
            [40] => 0
            [41] => 19836
            [42] => 0
            [43] => 18
            
        )

    [rate] => Array
        (
            [0] => 2.33
            [1] => 2.33
            [2] => 1.75
            [3] => 7.69
            [4] => 10.00
            [5] => 3.85
            [6] => 3.02
            [7] => 2.78
            [8] => 9.09
            [9] => 5.41
            [39] => 0
            [40] => 0
            [41] => 2.27
            [42] => 0
            [43] => 11.11
            
        )

    [deleteflag] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 1
            [8] => 0
            [9] => 0
            [39] => 0
            [40] => 0
            [41] => 0
            [42] => 1
            [43] => 0
            
        )

    [l2rate] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 1.75
            [3] => 1.75
            [4] => 1.75
            [5] => 1.75
            [6] => 3.02
            [7] => 3.02
            [8] => 3.02
            [9] => 3.02
            [39] => 0
            [40] => 0
            [41] => 2.27
            [42] => 2.27
            [43] => 2.27
            
        )

)

Answer : HOW TO SORT MULT-DIM ARRAY IN PHP

I would pop off your rate array so you sort it by itself using asort (which maintains indexes).

so...
$rate_array = array[rate];
asort($rate_array)

now you have an array of all the rates and indexes in the right order. Now, I would break apart all of the arrays then rebuild one big one with some code kind of like

foreach($rate_array as $key=>$value){
    $id_value = $id_array[$key];
    array_push($new_id_array);
    etc...
}
Random Solutions  
 
programming4us programming4us