Re: Finding a value in an array
| From: | Brian Clark | Date: | Mon, 08 Jan 2001 21:36:30 +0000 |
| Subject: | Re: Finding a value in an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-33324@lists.php.net to get a copy of this message | ||
Hello Todd,
(TC == "Todd Cary") todd@aristesoftware.com writes:
TC> Other than looping through an array, is there a Find function to
TC> see if a value is in an array?
PHP 4.x:
http://www.php.net/manual/html/function.in-array.html
PHP 3.x:
<?php
$array = array('stuff','foo');
function phpInArray($string, $array)
{
while(list(,$val) = each($array))
{
if($val == $string) return true;
}
return false;
}
print(! phpInArray('foo', $array) ? 'Not found' : 'In array');
?>
TC> I need to add values to an array, but I want to check to see if
TC> the value is already in the array where the values are generated
TC> by the random number generator.
-Brian