I'm trying to return all results from a large array that contain 'tags' that were intended to be searched through.
Hopefully I can explain this clearly, the array to be searched through looks like this:
array(
0 => 'DogCatSheepBlue WhaleShark',
1 => 'CatPigGoatOtter',
2 => 'ElephantTigerDogBlue WhaleGoat',
3 => 'SeahorseSnakeGoatLion',
....
);
There's an input box you can enter your search into, so for example if you enter Cat Whale
, how can I return results 0
1
and 2
of the array?
When a 'space' is entered into the search box, it should consider those words separately. For example, if you searched GoatSeahorse
, it shouldn't return any of the results above, even though Goat
and Seahorse
are technically both contained in array item 3
.
The array is returned from a MySQL query on page load, and the search input is forwarded through jQuery AJAX to the PHP code to create the new, filtered array list, which is then passed back to the HTML page.
Hopefully that makes sense - any advice is greatly appreciated. I'd also be more than happy to hear if there's an easier way to achieve this, even if it involves storing the array or MySQL fields in a different format.
Thanks!