Re: array search

From: Date: Sun, 23 Jan 2005 16:26:58 +0000
Subject: Re: array search
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-207087@lists.php.net to get a copy of this message
Malcolm wrote:
Hello All, I've been trying for days now to make this work. I'm trying to search my array for a value and return the key. I get the visitor's IP and try this -- this is the latest, I've tried a few functions to echo the name associated with the viz_ip. $viz_ip= $_SERVER['REMOTE_ADDR']; $byte_ip= array( "204.126.202.56"=>"Mark", "63.230.76.166"=>"Bob", "63.220.76.165"=>"John", ); function _array_search ($viz_ip, $byte_ip) { foreach($byte_ip as $key => $val) {
       if ($viz_ip === $key) {
           return($val);
       }
} return(False); }
try: function getValueInArr($val, $arr) { $val = (string)$val; return is_array($arr) && isset($arr[$val]) ? $arr[$val]: false; } but maybe the $viz_ip really _isn't_ set in the array you have?
I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong. I've read the examples at php.net but I just can't get it. Some help or even a hint ? best regards, malcolm


« previous php.general (#207087) next »