Sorting and slicing array, based on another "weight" array?
Your implementation seems fine.
The only improvement I see is to not preserve the ordering when you slice.
So instead of:


$arrAllowedKeys = array_slice($arrWeight, 0, self::METRICS_BREAKDOWN_LIMIT, true);



This is all you need:

$arrAllowedKeys = array_slice($arrWeight, 0, self::METRICS_BREAKDOWN_LIMIT);




The title of your question is "sorting and slicing array",
but the input array is not sorted.
During the process, only the calculated array of weights is sorted,
the original is not.

If the input is this:

$arr = array(
'apple' =&gt; array(1, 5, 3, 4, 0, 0),
'water' =&gt; array(0, 1, 2, 3, 4, 5),
'beer' =&gt; array(0, 0, 0, 0, 0, 0)
);


Then the output will be:

$arr = array(
'apple' =&gt; array(1, 5, 3, 4, 0, 0),
'water' =&gt; array(0, 1, 2, 3, 4, 5)
);


In other words, the input array is sliced, but not sorted.



What happens to elements with the same weight, around the self::METRICS_BREAKDOWN_LIMIT index? For example, if self::METRICS_BREAKDOWN_LIMIT = 1, and the initial array is this:

$arr = array(
'water' =&gt; array(1, 2, 3),
'apple' =&gt; array(1, 2, 3),
'beer' =&gt; array(1, 2, 3)
);


Which record will be in the result? It depends on whether arsort is using a stable sorting algorithm (not so easy to find in the docs of arsort). If arsort is stable, insertion order will be preserved, and the answer will be water. Otherwise it can be any of these. It would be a good idea to add a comment in the code about this.