search all keys of an associative array (containing key => value, instead of [0],[1],[2]) for a substring, return value associated with that key/property.

/* returns the $value of the element,
* if $search_for_this_string is found in one of the keys of $element
* otherwise returns null
* */
function ArraySearchForStringInAllKeys($this_string,$array_assoc)
  $looking_for_that_value = null;
  foreach ($array_assoc as $key => $value)
    if(stripos($key, $this_string) !== false) // check if $key contains $this_string
      $looking_for_that_value = $value;

  return $looking_for_that_value;

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!