note 90362 added to function.array-diff

From: Date: Fri, 17 Apr 2009 18:55:03 +0000
Subject: note 90362 added to function.array-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-153451@lists.php.net to get a copy of this message
In response to the function suggested by ottodenn at gmail dot com: You should probably also check if one of the arrays is empty. This one worked for me and ran fine in a suite of unit tests: function getArrayChanges($a1, $a2) { if (empty($a1) || empty($a2)) { return !empty($a1) ? $a1 : $a2; } $ar = array(); foreach ($a2 as $k => $v) { if (!is_array($v) || !is_array($a1[$k])) { if ($v !== $a1[$k]) { $ar[$k] = $v; } } else { if ($arr = $this->getArrayChanges($a1[$k], $a2[$k])) { $ar[$k] = $arr; } } } return $ar; } ---- Server IP: 217.13.201.10 Probable Submitter: 85.177.117.40 ---- Manual Page -- http://www.php.net/manual/en/function.array-diff.php Edit -- https://master.php.net/note/edit/90362 Del: integrated -- https://master.php.net/note/delete/90362/integrated Del: useless -- https://master.php.net/note/delete/90362/useless Del: bad code -- https://master.php.net/note/delete/90362/bad+code Del: spam -- https://master.php.net/note/delete/90362/spam Del: non-english -- https://master.php.net/note/delete/90362/non-english Del: in docs -- https://master.php.net/note/delete/90362/in+docs Del: other reasons-- https://master.php.net/note/delete/90362 Reject -- https://master.php.net/note/reject/90362 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153451) next »