Skip to content

Instantly share code, notes, and snippets.

@Inzman
Created August 16, 2018 05:02
Show Gist options
  • Select an option

  • Save Inzman/9b03b7ec114df236b65190611b4d72c1 to your computer and use it in GitHub Desktop.

Select an option

Save Inzman/9b03b7ec114df236b65190611b4d72c1 to your computer and use it in GitHub Desktop.
Search multidimensional array by value
$key = array_search($item_id, array_column($array_name, 'id'));
____________________________
function search($array, $key, $value)
{
$results = array();
if (is_array($array))
{
if (isset($array[$key]) && $array[$key] == $value)
$results[] = $array;
foreach ($array as $subarray)
$results = array_merge($results, search($subarray, $key, $value));
}
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment