Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mae829
Last active September 10, 2020 23:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mae829/21ab3608ec6b60225ed9883ced2f2f22 to your computer and use it in GitHub Desktop.
Save mae829/21ab3608ec6b60225ed9883ced2f2f22 to your computer and use it in GitHub Desktop.
Code to check for a key inside a deep array
<?php
// Deep search array for key.
function multi_key_exists( array $arr, $key ){
// is in base array?
if ( array_key_exists($key, $arr) ) return true;
// check arrays contained in this array.
foreach ( $arr as $element ) {
if ( is_array( $element ) && multi_key_exists( $element, $key ) ){
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment