I have a standard multi dimensional array listed below that will house my customers faq articles. The articles will include a title, a description and various tags per article. I am trying to setup a form on my website where a visitor can search any content inside the array. If there is a match, the site will return the article that matched the tag that was searched for.
My questions.
- Is this the best way to offer an FAQ search or should I be looking at something doing something with javascript and json?
- How should I search through the array and identify the correct article that includes the tag the visitor searched for?
Here is my array.
function get_articles_all() {
$articles = array();
$articles[0] = array(
"title" => "What port does the Cisco TSP use?",
"body" => "TAPI talks to the TAPI Service Provider (TSP) and the TSP talks to the CTI manager through port 2748.",
"tag" => array("port","cisco")
);
$articles[1] = array(
"title" => "Title of second article.",
"body" => "Body of second article. Body of second article. Body of second article. Body of second article. Body of second article. Body of second article. Body of second article. Rocky.",
"tag" => array("second","number2")
);
$articles[2] = array(
"title" => "Title of third article.",
"body" => "Body of third article. Body of third article. Body of third article. Body of third article. Body of third article. Body of third article. Body of third article. Rocky.",
"tag" => array("third","number3")
);
return $articles;
}
Here is my search function.
function article_tag_search($t) {
$tagResults = array();
$all = get_articles_all();
foreach ($all as $article => $key) {
if (stripos($key,$t) !== false) {
$tagResults[] = $article;
}
}
return $tagResults;
}
Here is what I am using to test the code.
$test = article_tag_search("port");
echo '<pre>';
print_r($test);
echo '</pre>';
It results in the following output.
Array
(
[0] => 0
[1] => 1
[2] => 2
)
Any assistance would be greatly appreciated.
Dustin