I have an odd question which I cannot find an answer to on Google or SO.
I have an array containing all the bits of information about the pages on my website. So the array contains multiple of the arrays like the example below:
'home' =>
array (size=7)
'title' => string '' (length=0)
'url' => string 'home.php' (length=8)
'mobile' => string 'home.php' (length=8)
'keywords' => string '' (length=0)
'description' => string 'test123' (length=126)
'login_needed' => boolean false
'original_page' => string 'home' (length=4)
What I need to do is to find each array that contains a value that comes from a search bar. For example if the user searches for "bruidsmode" every array that contains "bruidsmode" should be put into another array which I can then output into elements to display on the website.
Below you will find a stripped example of what I have on my page. (I tried making a working example but was unable to do so):
<?php
$config['menu']["home"] = array (
'title' => '',
'url' => 'home.php',
'mobile' => 'home.php',
'keywords' => '',
'description' => '',
'login_needed' => FALSE
);
$config['menu']["bruidsmode"] = array (
'title' => '',
'url' => 'bruidsmode.php',
// 'mobile' => 'bruidsmode.php',
// 'mobile' => 'bruidsmode.php',
'keywords' => '',
'description' => '',
'login_needed' => TRUE,
'robot' => FALSE
);
if(isset($_POST['generalsearch']) && isset($_POST['generalsearchresult'])){
// Put search value into variable
$searchvalue = $_POST['generalsearchresult'];
// Fill variable with all page items
$array = $config['menu'];
// Set search cretaria to search in array
$key = $searchvalue;
// Search for key value inside array
$result = @$array[$key] ?: null;
if($result == null){
echo "Geen resultaten gevonden...";
}else{
var_dump($result);
}
}
?>
<form method="POST">
<input type="text" name="generalsearchresult">
<input type="submit" name="generalsearch">
</form>
The above code works but only outputs arrays which exactly match the search criteria. So for example the searchterm "bruidsmode" with the above code outputs only the page "bruidsmode" but not the page "bruidsmode-overzicht" for example.
I hope the above is understandable, if not please tell me how to improve it.
Kind regards, Robbert
$config['menu']contains. It looks like its a multidimentional array, and you are searching against the top level keys ('home', 'bruidsmode'...). Its not clear if you intend to search against the lower level array values (title. description etc), or if you would want to return multiple results$arrayon line #10.