You don't understand what the function I wrote does.I intended for it to just point you in the right direction. I should have given a better explanation than one comment. Here is a more complete example.
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Search</title>
</head>
<body>
<?php
//array_find_value Array Search Value
function array_find_value($array,$svalue){
$return = array();
if(empty($svalue)){
return $array;
}
foreach($array as $key=>$value){
if(stristr($value,$svalue) !== FALSE){
$return[$key] = $value;
}
}
return $return;
}
function search($array,$search){
$find = array_find_value($array,$search);
echo '<p>You searched for "'.$search.'". There were '.count($find).' results.</p>';
echo ' <form method="get" action="'.$_SERVER['PHP_SELF'].'"><input type="text" name="name"><button type="submit">Search Again</button></form>';
echo '<ol>';
foreach($find as $key=>$value){
echo "<li>".$key."</li>";
}
echo '</ol>';
}
if(!empty($_REQUEST['name'])){
$name = $_REQUEST['name'];
}
else{
$name = '';
}
$names = array( "Alex" => "alex" , "Amanda" => "amanda" , "John" => "john" , "Smith" => "smith" , "Jewell" => "alex jewell" );
search($names,$name);
?>
</body>
</html>
Bookmarks