Suppose I have an array which is in the below:
Array
(
[0] => Array
(
[name] => playstation sony 3 slim 320gb
)
[1] => Array
(
[name] => sony xperia acro s
)
[2] => Array
(
[name] => sony xperia tipo
)
[3] => Array
(
[name] => sony ericsson xperia arc s
)
[4] => Array
(
[name] => sony xperia go
)
[5] => Array
(
[name] => sony playstation 4
)
)
Now I want to filter the array based on the search value and sort the array by the based on most relevant (by shortest length).
My request data is:
$request = 'sony';
I'm expecting the following results:
Array
(
[0] => Array
(
[name] => sony xperia go
)
[1] => Array
(
[name] => sony xperia tipo
)
[2] => Array
(
[name] => sony playstation 4
)
[3] => Array
(
[name] => sony xperia sony acro ss
)
[4] => Array
(
[name] => sony ericsson xperia arc s
)
[5] => Array
(
[name] => playstation Sony 3 slim 320gb
)
)