Hello All,
Think i’m being quite thick here, but can’t work it out. I have a page where I use $_GET on a URL string ie:
.php?fruit=apples
$fruits = array(85 => "apples", 64 => "oranges", 95 => "pears");
if (in_array($_GET['fruit'], $fruits)) {
//echo $key;
}
So why how do I echo out the $key for each using this?
Thanks
Chris
Try this and let us know what happens. Also remember that the item being searched for IS case sensitive. That means Apple isn’t the same as apple.
$fruits = array(85 => "apples", 64 => "oranges", 95 => "pears");
if ((isset($_GET['fruit'])) and (in_array($_GET['fruit'], $fruits)))
{
echo 'In array';
}
Thanks for the help, but in the example where you have echoed out ‘In array’ I want to echo out the key, ie 85, 64 or 95 which is where i’m stuck.
php.net/array_search
array_search() is what you want