Skip to content

Instantly share code, notes, and snippets.

@savasdersimcelik
Last active September 26, 2020 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save savasdersimcelik/e9e8d2befc305c191b0087ebd5a85a75 to your computer and use it in GitHub Desktop.
Save savasdersimcelik/e9e8d2befc305c191b0087ebd5a85a75 to your computer and use it in GitHub Desktop.
PHP Array Deep Search | Returns the value of an element with a key value in an array of uncertain depth.
if (! function_exists('array_deep_search'))
{
/**
* Author : Savaş Dersim ÇELİK
* Returns the value of an element with a key value in an array of uncertain depth.
*
* @param array $array
* @param string $key
*
* @return mixed|false
*/
function array_deep_search(array $array, string $key)
{
if (isset($array[$key]))
{
return $array[$key];
}
foreach ($array as $value)
{
if (is_array($value))
{
$result = array_deep_search($value, $key);
if ($result)
{
return $result;
}
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment