This question is different than others, as it's focus is on sorting an array with a static class method rather than the typical procedural approach.
I am look for a very performant way to implement the function sortByKeyValue below. Other somewhat related answers are focused on getting the job done, this question is more about getting the job done and getting it done very quickly (as a static method).
Anyone want to take a crack at it? I'll probably throw some bounty on this question to squeeze out the performance junkies. :)
<?php
$data = array(
array('name' => 'B', 'cheesy' => 'bacon'),
array('name' => 'C', 'delicious' => 'tacos'),
array('name' => 'A', 'lovely' => 'viddles'),
);
class MyArray {
public static function sortByKeyValue($array, $key, $direction = 'ASC') {
// Do the thing
// Help me!
return $array;
}
}
$data = MyArray::sortByKeyValue($data, 'name');
// Should output the name key in order
// I am not including the garbage keys I threw in, but they should be there too)
// [{"name": "A"},{"name": "B"},{"name": "C"}]
?>