I have set of data that I need help with. I need to make a difficult calculation and array sort through several multidimensional arrays and the logic and syntax is giving me a headache.
Basically what I need it:
- an array of keywords
- I need to query a database and store some results for each keyword. (ID and Count of keyword matches)
- I need to then flip the array around so instead of keywords being the parent element, it's IDs with the count of matches for each keyword within
- I need to perform a calculation to get a single number from these number of matches
- I need to sort the array so I can see which ID yielded the highest match value in the database, so I can query and output the relevant data.
I know how I am going to do the calculation for the relevancy now, it's just I've only briefly worked with single dimension arrays and I don't know how to syntactically represent what I need with this example. Could anyone give me a hand?
Here is a sample of what I want - not sure if this is syntactically the best way to show you, but hopefully you'll get the picture:
Array
(
[Keywords] => Array
(
["wax"] => Array
(
[ID] => 1
[Match] => 8
[ID] => 2
[Match] => 10
)
["hard"] => Array
(
[ID] => 1
[Match] => 2
[ID] => 2
[Match] => 37
)
)
Then this array would need to be translated to:
Array
(
[ID] => Array
(
["1"] => Array
(
[Keyword] => "wax"
[Match] => 8
[Keyword] => "hard"
[Match] => 10
)
["2"] => Array
(
[Keyword] => "wax"
[Match] => 2
[Keyword] => "hard"
[Match] => 37
)
)