note 50385 added to ref.array
| From: | Frando at osu1 dot php dot net | Date: | Sat, 26 Feb 2005 13:58:56 +0000 |
| Subject: | note 50385 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85582@lists.php.net to get a copy of this message | ||
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."
?>
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50385
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50385&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50385&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50385&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50385&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50385&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50385&report=yes
Search -- http://master.php.net/manage/user-notes.php