How am I able to use an associative array key to search for a string and echo the value?
<?php
$haystack = "My name is Allen";
//works with this style array
$names = array("Mike", "Joe", "Bob", "allen");
echo arrayinstr($haystack, $names);//echo's allen
//How do I get associative style arrays to echo the sex (male) instead of "allen"? (male,female,alien)
$names["Bob"] = male;
$names["Sally"] = female;
$names["Charlie"] = male;
$names["Allen"] = male;
$names["Android"] = alien;
$names["ET"] = alien;
$nameS["Brad"] = male;
function arrayinstr($haystack, $needle) {
foreach($needle as $value) {
$haystack = strtolower($haystack);
if (!strpos($haystack, $value) === false)
$foundit = $value;
}
return $foundit;
}
?>