note 73972 modified in function.array-diff-assoc by bobby

From: Date: Tue, 20 Mar 2007 17:26:56 +0000
Subject: note 73972 modified in function.array-diff-assoc by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124638@lists.php.net to get a copy of this message
A small modification for array_diff_assoc_recursive from 'sc1n at yahoo dot com' , to not display any notices if a key don't exist and if error_reporting is set to E_ALL: <?php function array_diff_assoc_recursive($array1, $array2) { foreach($array1 as $key => $value) { if(is_array($value)) { if(!isset($array2[$key])) { $difference[$key] = $value; } elseif(!is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = array_diff_assoc_recursive($value, $array2[$key]); if($new_diff != FALSE) { $difference[$key] = $new_diff; } } } elseif(!isset($array2[$key]) || $array2[$key] != $value) { $difference[$key] = $value; } } return !isset($difference) ? 0 : $difference; } ?> --was-- A small modification for array_diff_assoc_recursive from 'sc1n at yahoo dot com' , to not display any notices if a key don't exist and if error_reporting is set to E_ALL: <?php function array_diff_assoc_recursive($array1, $array2) { foreach($array1 as $key => $value) { if(is_array($value)) { if(!isset($array2[$key])) { $difference[$key] = $value; } if(!is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = array_diff_assoc_recursive($value, $array2[$key]); if($new_diff != FALSE) { $difference[$key] = $new_diff; } } } elseif(!isset($array2[$key]) || $array2[$key] != $value) { $difference[$key] = $value; } } return !isset($difference) ? 0 : $difference; } ?> http://php.net/manual/en/function.array-diff-assoc.php

« previous php.notes (#124638) next »