note 39822 modified in function.array-intersect-assoc by aidan

From: Date: Sat, 26 Jun 2004 07:33:14 +0000
Subject: note 39822 modified in function.array-intersect-assoc by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71731@lists.php.net to get a copy of this message
In response to the first posting below, try this: <?php function array_intersect_assoc_recursive(&$arr1, &$arr2) { if (!is_array($arr1) || !is_array($arr2)) { return $arr1 == $arr2; // or === for strict type } $commonkeys = array_intersect(array_keys($arr1), array_keys($arr2)); $ret = array(); foreach ($commonkeys as $key) { $ret[$key] =& array_intersect_assoc_recursive($arr1[$key], $arr2[$key]); } return $ret; } ?> --was-- In response to the first posting below, try this: function &array_intersect_assoc_recursive(&$arr1, &$arr2) { if (!is_array($arr1) || !is_array($arr2)) { return $arr1 == $arr2; // or === for strict type } $commonkeys = array_intersect(array_keys($arr1), array_keys($arr2)); $ret = array(); foreach ($commonkeys as $key) { $ret[$key] =& array_intersect_assoc_recursive($arr1[$key], $arr2[$key]); } return $ret; } http://php.net/manual/en/function.array-intersect-assoc.php

« previous php.notes (#71731) next »