
array_search_string
By: a guest on
Mar 14th, 2012 | syntax:
PHP | size: 0.58 KB | hits: 25 | expires: Never
function array_search_string($needle, array $haystack)
{
$found = false;
if (strpos($needle, '[') !== false) {
$k = preg_split('~\]?\[~', substr($needle, 0, -1));
$i = 1;
$t = count($k);
foreach ($k as $k) {
if ((array)$haystack === $haystack) {
if (array_key_exists($k, $haystack)) {
$haystack = $haystack[$k];
$i === $t && ($found = true);
}
}
++$i;
}
} elseif (array_key_exists($needle, $haystack)) {
$haystack = $haystack[$needle];
$found = true;
} else {
$haystack = null;
}
return $found ? $haystack : null;
}