I have this associative array that I want to sort in a custom order (not just alphabetically):
$arr = [
'1' => 'Lorem Ipsum 1',
'2' => 'Lorem Ipsum 3',
'3' => 'Lorem Ipsum 2',
'4' => 'Text A',
'5' => 'Text B',
'6' => 'Text C',
'7' => 'Lorem Ipsum 4',
'8' => 'Text D',
'9' => 'Text E',
];
I need this output:
$arr = [
'4' => 'Text A',
'5' => 'Text B',
'6' => 'Text C',
'8' => 'Text D',
'9' => 'Text E',
'1' => 'Lorem Ipsum 1',
'3' => 'Lorem Ipsum 2',
'2' => 'Lorem Ipsum 3',
'7' => 'Lorem Ipsum 4'
];
How the array needs to be sorted (keep key-value association)
- Sort Array Alphabetically
- After this, all values that start with Text have to be on top
I already tried it with the function uasort, but could not find out how to sort them starting with Text.
Thank you