<?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"; function sort_most_needles(&$array, $str) { $needles = explode(" ", $str); usort($array, function ($a, $b) use ($needles) { return array_uintersect($needles, explode(" ", $b['title']), 'strcasecmp') <=> array_uintersect($needles, explode(" ", $a['title']), 'strcasecmp'); }); } sort_most_needles($arr, $str); var_export($arr);
You have javascript disabled. You will not be able to edit any code.