note 95071 deleted from function.in-array by bjori

From: Date: Fri, 01 Jan 2010 17:32:54 +0000
Subject: note 95071 deleted from function.in-array by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164516@lists.php.net to get a copy of this message
Note Submitter: mert dot hurturk at gmail dot com ---- If you are trying to find out if given two arrays' keys match recursively, you can use this function: <?php function array_keys_match($arr1, $arr2) { $return = true; foreach ($arr1 as $key => $value) { if (isset($arr2[$key])) { if (strtolower(gettype($arr1[$key])) == 'array') { $return = array_keys_match($arr1[$key], $arr2[$key]); } } else { $return = false; break; } } return $return; } Example: $arr1 = array( 'key1' => array( 'key1a' => 'some value' ), 'key2' => 'heyoo' ); $arr2 = array( 'key1' => array( 'key1a' => 'some value' ), 'key2' => 'heyoo' ); var_dump(array_keys_match($arr1, $arr2)); // returns bool(true) $arr3 = array( 'key1' => array( 'key1a' => 'some value' ), 'key2' => array( 'key2a' => 'some value', 'key2b' => 'some value' ) ); $arr4 = array( 'key1' => array( 'key1a' => 'some value' ), 'key2' => array( 'key2a' => 'some value', 'different_key' => 'some value' ) ); var_dump(array_keys_match($arr3, $arr4)); // returns bool(false) ?>

« previous php.notes (#164516) next »