Note Submitter: wcc at techmonkeys dot org
----
<?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;
}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.