0

I want to sort a php array in a way that it compares to a certain string and

  1. Exact match of the string is in the top
  2. the rest need to be sorted according to relevance to the string. The most similar string to be next and so on.

I am getting the array remotely so i do not have any control over sql statements
I have googled and couldn't find a satisfying answer.
Thank you in advance

1 Answers1

4

You could use usort with a callback function that utilizes levenshtein() to sort your array.

Benjamin Paap
  • 2,744
  • 2
  • 21
  • 33