我正在开发一个常见问题(常见问题) PHP脚本,我想为用户实现一种方式来搜索常见问题。这是一个小脚本,所以我将类别和常见问题放在一个数组中,如下所示:
$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')); 现在,我要做的是从表单中获取一个搜索查询(使用GET请求),并在此数组中搜索该搜索查询。我想知道我该怎么做?我必须先解析搜索查询才能搜索数组吗?为此,我可以使用array_search()函数吗?或者我必须编写自己的代码来迭代数组吗?我还想知道,使用不同的方法(XML、SQL等)来存储FAQ是否更好?
发布于 2013-02-05 15:16:26
我会使用一个数据库来回答这些问题,比如:
id int not null auto increment primary_key,
question text not null,
answer text not null然后,我将执行where like查询:
...
WHERE question LIKE '%questionsearchvalue%'
...发布于 2013-02-05 15:19:17
请看一下这个帖子,特别是阅读所有用户的评论。你可能会得到你想要的。
http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/
发布于 2013-02-05 15:08:49
您可以使用另一种方法来解决它。回显所有常见问题,然后使用jquery突出显示插件在html中搜索。
Here is the link
https://stackoverflow.com/questions/14701831
复制相似问题