note 50385 deleted from ref.array by nlopess
| From: | nlopess@php.net | Date: | Sun, 27 Feb 2005 11:01:28 +0000 |
| Subject: | note 50385 deleted from ref.array by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-85628@lists.php.net to get a copy of this message | ||
Note Submitter: Frando
----
There is a function to check wether a given key exists in an array or not, but there isn't a
function to do the same for a value.
This little function checks if a given value exists in the array.
array_value_exists returns TRUE if $value is a value in $search.
<?php
function array_value_exists($value, $search) {
foreach ($search as $array_key=>$array_value) {
if ($array_value == $value)
return TRUE;
}
return FALSE;
}
?>
A little example:
<?php
$colors = array ('color1'=>'red', 'color2'=>'blue',
'color3'=>'green');
$color2check = "blue";
if (array_value_exists($color2check, $colors))
echo "$color2check is a valid entry."
?>