Advertisement
Guest User

array_search_string

a guest
Mar 14th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. function array_search_string($needle, array $haystack)
  2. {
  3.  
  4.     $found = false;
  5.     if (strpos($needle, '[') !== false) {
  6.         $k = preg_split('~\]?\[~', substr($needle, 0, -1));
  7.         $i = 1;
  8.         $t = count($k);
  9.         foreach ($k as $k) {
  10.             if ((array)$haystack === $haystack) {
  11.                 if (array_key_exists($k, $haystack)) {
  12.                     $haystack = $haystack[$k];
  13.                     $i === $t && ($found = true);
  14.                 }
  15.             }
  16.             ++$i;
  17.         }
  18.     } elseif (array_key_exists($needle, $haystack)) {
  19.         $haystack = $haystack[$needle];
  20.         $found = true;
  21.     } else {
  22.         $haystack = null;
  23.     }
  24.     return $found ? $haystack : null;
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement