I have a multidimensional array I need to sort based on multiple criteria and I'm not sure what the optimal way to do that is.
Here is what I'm working with:
array {
[0]=>
array {
["itemid"]=>
string "3135475"
["model"]=>
array {
["Model"]=>
string "MK1931"
}
["brand"]=>
array {
["Brand"]=>
string "Castles"
["Manufacturer"]=>
string "Castles Int'l, LTD"
}
["views"]=>
string "53465"
}
[1]=>
array {
["itemid"]=>
string "3616546"
["model"]=>
array {
["Model"]=>
string"1931"
["PartNumber"]=>
string "MK1931"
}
["brand"]=>
array {
["Brand"]=>
string "Castles"
["Manufacturer"]=>
string "Castles Int'l, LTD"
}
["views"]=>
string "134465"
}
[2]=>
array {
["itemid"]=>
string "1024567"
["model"]=>
array {
["PartNumber"]=>
string "MK1931"
}
["brand"]=>
array {
["Brand"]=>
string "Castles"
}
["views"]=>
string "253465"
}
[3]=>
array {
["itemid"]=>
string "35463810"
["model"]=>
array {
["PartNumber"]=>
string "MK1931-170952"
}
["brand"]=>
array {
["Brand"]=>
string "Product By Castles"
}
["views"]=>
string "265"
}
}
I need to find the itemid in the array that has both the highest # of brand matches to "Castles" and the highest # of model matches to "MK1931" and then out that I need the element with the highest # of views. If an element doesn't have any brand and model matches it should be discarded before even checking the views.
In this case, just eyeballing it, it would be element #2 (itemid 1024567).
I'm trying to figure out the fastest, least CPU intensive method of getting element #2 using PHP.