Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement