note 57096 deleted from function.in-array by felipe

From: Date: Sun, 30 Dec 2007 18:57:47 +0000
Subject: note 57096 deleted from function.in-array by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134484@lists.php.net to get a copy of this message
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; } ?>

« previous php.notes (#134484) next »