I would like to sort a php array starting with a value I set
Example:
$array = array();
$array['test'] = 'banana';
$array['test2'] = 'apple';
$array['test3'] = 'pineapple';
$array['test4'] = 'orange';
How do I sort it so that ‘orange’ is the first result then it sorts alphabetical from then on.
So it would be
orange
apple
banana
pineapple
Any help on this would be greatly appreciated.
You can create your own custom sorting function and then use
usort(oruasortif you want to preserve your array keys — thanks to Isaac in the comments for the reminder) to sort your array with it: