note 57096 added to function.in-array
| From: | wcc at techmonkeys dot org | Date: | Fri, 23 Sep 2005 14:04:21 +0000 |
| Subject: | note 57096 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95659@lists.php.net to get a copy of this message | ||
<?php
/**
* Search for a key and value pair in the second level of a multi-dimensional array.
*
* @param array multi-dimensional array to search
* @param string key name for which to search
* @param mixed value for which to search
* @param boolean preform strict comparison
* @return boolean found
* @access public
*/
function findKeyValuePair($multiArray, $keyName, $value, $strict = false)
{
/* Doing this test here makes for a bit of redundant code, but
* improves the speed greatly, as it is not being preformed on every
* iteration of the loop.
*/
if (!$strict)
{
foreach ($multiArray as $multiArrayKey => $childArray)
{
if (array_key_exists($keyName, $childArray) &&
$childArray[$keyName] == $value)
{
return true;
}
}
}
else
{
foreach ($multiArray as $multiArrayKey => $childArray)
{
if (array_key_exists($keyName, $childArray) &&
$childArray[$keyName] === $value)
{
return true;
}
}
}
return false;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57096
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57096&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57096&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57096&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57096&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57096&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57096&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57096&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57096&report=yes
Search -- http://master.php.net/manage/user-notes.php