I'm trying to sort the second-level values based on a specific keyword. In this case that keyword is red.
If I inspect the steps in the callback function it seems to work, but the final result is unchanged. It also sorts the top-level keys alphabetically.
$data = array(
'foo' => array(
'red', 'green'
),
'bar' => array(
'yellow', 'red'
),
);
print_r($data);
uasort($data, function($data) {
$matches = preg_grep("/red/", $data);
$rest = array_diff($data, $matches);
$order = array_merge($matches, $rest);
return $order;
});
print_r($data);