<?php
$arr = array(array("id" => 1,"title" => "Hello world", "body" => "Hi Jude All this is my content"),
array("id" => 2,"title" => "Hello world Boy", "body" => "Hi All this is my content Girl"),
array("id" => 3,"title" => "hello Kids", "body" => "Hi All this is my content Kid"),
array("id" => 4,"title" => "Hello World Jude", "body" => "Hi All this is my content Jude"),
array("id" => 5,"title" => "Hello World Jude January", "body" => "Hi All this is my content Jan"),
array("id" => 6,"title" => "Hello World January June Lord", "body" => "Hi All this is my content Jan Jude Lord"));
$str = "hello world january jude";
$arr2 = sort_most_exists_asc($arr, $str);
var_dump($arr2);
function sort_most_exists_asc($array, $str) {
usort($array, function ($a, $b) use ($str) {
$aa = count(array_uintersect(explode(" ", $str), explode(" ", $a['title']), 'strcasecmp'));
$bb = count(array_uintersect(explode(" ", $str), explode(" ", $b['title']), 'strcasecmp'));
return $bb - $aa;
});
return $array;
}