I am developing a FAQ (Frequently Asked Question) PHP script and I want to implement a way for users to search the FAQs. This is a small script so I have the categories and FAQs in an array as shown below:
$qa = array();
$qa['Getting Started'] = array(array('What is 1+1?', '2'), array('What is the square root of 16?', 'The square root is 4'));
$qa['Installation'] = array(array('What is 2+2?', '4'), array('What is the square root of 64?', 'The square root is 8'));
Now, what I want to do is take a search query from a form (using a GET request) and search this array for that search query. I was wondering how I might go about doing this? Would I have to parse the search query first so that the array can be searched? Would I be able to use the array_search() function for this or would I have to write my own code to iterate through the array? I was also wondering if the FAQs are better to be stored using a different method (XML, SQL, etc) to do this?
I would use a database for the questions something like:
Then I would do a where like query: