note 115725 added to function.array-diff-key
| From: | rhallsey at yahoo dot com | Date: | Sat, 13 Sep 2014 00:45:37 +0000 |
| Subject: | note 115725 added to function.array-diff-key | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200436@lists.php.net to get a copy of this message | ||
Here's a simple function that returns true if all keys in the first array are found in the
second array, and false if they aren't.
function same_keys ($a1, $a2) {
$same = false;
if (!array_diff_key($a1, $a2)) {
$same = true;
foreach ($a1 as $k => $v) {
if (is_array($v) && !same_keys($v, $a2[$k])) {
$same = false;
break;
}
}
}
return $same;
}
To check if two arrays have the same structure, ignoring values, execute the function twice, the
second time with the arguments reversed.
----
Server IP: 216.194.115.244
Probable Submitter: 64.175.42.200
----
Manual Page -- http://php.net/manual/en/function.array-diff-key.php
Edit -- https://master.php.net/note/edit/115725
Del: integrated -- https://master.php.net/note/delete/115725/integrated
Del: useless -- https://master.php.net/note/delete/115725/useless
Del: bad code -- https://master.php.net/note/delete/115725/bad+code
Del: spam -- https://master.php.net/note/delete/115725/spam
Del: non-english -- https://master.php.net/note/delete/115725/non-english
Del: in docs -- https://master.php.net/note/delete/115725/in+docs
Del: other reasons-- https://master.php.net/note/delete/115725
Reject -- https://master.php.net/note/reject/115725
Search -- https://master.php.net/manage/user-notes.php