I have the following array:
Array
(
[medium_priority] => Array
(
[0] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 60
)
)
[high_priority] => Array
(
[0] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 95
)
[1] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 85
)
[2] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 80
)
)
[low_priority] => Array
(
[0] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 20
)
[1] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 30
)
)
)
Using PHP, I want to get an array consisting of the five values with the highest weight, like this:
Array
(
[0] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 95
)
[1] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 85
)
[2] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 80
)
[3] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 60
)
[4] => Array
(
[module] => a
[block] => b
[message] => c
[weight] => 30
)
)
Of course, this could be accomplished by iterating over the array using a loop to 'flatten' the array and then sort it usort, but I think there should be an easier and faster way.
However, I can't figure out what that would be.
I hope you can help me!
LINQ. See phplinq.codeplex.com or plinq.codeplex.com.Disclosure:I have little experience w/ PHP and none w/ these LINQ implementations (beware some seem a bit "young"). I'm just glad to see this type of features coming to more languages and abstracting out the more common programming tasks.