Is there a way to assign a "priority score" to an array in PHP? Then sort based on that priority. Given my input:
Array(
[princeton] => Princeton
[stanford] => Stanford
[yale] => Yale
[mit] => MIT
[harvard] => Harvard
)
I would like the output to always have Harvard and Yale at the top, the rest alphabetically sorted:
Array(
[harvard] => Harvard
[yale] => Yale
[mit] => MIT
[princeton] => Princeton
[stanford] => Stanford
)
I checked out asort() which does the alphabetical and uasort() which is custom-defined, but I'm stuck on how I can "assign a priority". Any help would be appreciated!
uasort, you would define the sorting between 2 items. If neither is Harvard or Yale, do a strcmp, if one of them is, make it sort before the other, if both are, return 0 (unless you want harvard to sort before yale always, in which case, you could once again return a strcmp when both are harvard or yale).