Yet another PHP question. I’ve got two arrays: one string-based and the other numeric. The array of strings contains the names of various buildings. The numeric array tracks relevance of the search in relation to the buildings.
Example: I search for “Armory Building” (http://yoursite.com/search.php?building=Armory+Building)
I loop through all 25 buildings and display any containing one or more search terms (Armory and Building).
Armory Hall
Armory State Building
Armory Dining Hall Building
Obviously, if the search should bring up results based on relevance, the last two should appear FIRST. How do I sort it so that both arrays get re-ordered but maintain the same index, meaning I re-order the results based on relevance (the last 2 would have a “relevance” of 2 and the first result would have a “relevance” of 1).
In this case its not easy to do this. If you have 2 arrays, and you sort one of them, you need in the same time sort the other one and if elements has chenge, related elements need to be changed in 2nd array.
Better way is to keep all in one 2 dimensions array and sort it:
https://www.php.net/array_multisort
Also you could write tour own sorting function, here is example: