Advertisement
ryanharne

PHP Find nested associative array set by assc's Key & Value

Sep 25th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. function find_nested_assc_array_set_by_key($set = array(), $key, $lookfor, $very_similiar = true)
  2. {
  3.     if(empty($set))
  4.     {
  5.         return $set;
  6.     }
  7.  
  8.     foreach($set as $index => $st)
  9.     {
  10.         if(array_key_exists($key, $st) === false)
  11.         {
  12.             continue;
  13.         }
  14.  
  15.         if($very_similiar)
  16.         {
  17.             if( (!empty($st[$key])) && ($st[$key] == $lookfor) )
  18.             {
  19.                 return $st;
  20.             }
  21.         }
  22.         else
  23.         {
  24.             if( (!empty($st[$key])) && (strpos(strtolower($st[$key]),  strtolower($lookfor)) !== false) )
  25.             {
  26.                 return $st;
  27.             }
  28.         }
  29.     }
  30.  
  31.     return false;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement