Answer the question
In order to leave comments, you need to log in
How to make a relevant sorting for a query in an array?
There is a one-dimensional array with test sentences and there is a word. How to sort an array? In general, it’s like in Google, only everything is serious there, but I have an array.
Answer the question
In order to leave comments, you need to log in
The simplest is boolean search
www.machinelearning.ru/wiki/images/d/d2/IR.pdf
Well, let's say if you need to sort by the number of occurrences of a word in each text.
$text_arr = []; // массив тестов
$word = 'слово'; // искомое слово
usort($text_arr, function ($a, $b) use ($word) {
return substr_count($a, $word) >= substr_count($b, $word) ? -1 : 1;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question