note 127005 added to function.array-diff-assoc

From: Date: Sat, 23 Apr 2022 08:38:08 +0000
Subject: note 127005 added to function.array-diff-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-218305@lists.php.net to get a copy of this message
Recursive implementation accepting multiple n-level-arrays as parameters: ```php function recursiveDiff(...$arrays) { $first = array_shift($arrays); $diff = []; foreach ($first as $key => $value) { $values = array_map(function ($arr) use ($key) { if (is_array($arr) && !array_key_exists($key, $arr)) { return null; } return isset($arr[$key]) ? $arr[$key] : null; }, $arrs); if (in_array($value, $values)) { continue; } if (is_array($value)) { array_unshift($values, $value); $diff[$key] = call_user_func_array(__FUNCTION__, $values); continue; } $diff[$key] = $first[$key]; } return $diff; } ``` ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 102.89.34.249) ---- Manual Page -- https://php.net/manual/en/function.array-diff-assoc.php Edit -- https://main.php.net/note/edit/127005 Del: integrated -- https://main.php.net/note/delete/127005/integrated Del: useless -- https://main.php.net/note/delete/127005/useless Del: bad code -- https://main.php.net/note/delete/127005/bad+code Del: spam -- https://main.php.net/note/delete/127005/spam Del: non-english -- https://main.php.net/note/delete/127005/non-english Del: in docs -- https://main.php.net/note/delete/127005/in+docs Del: other reasons-- https://main.php.net/note/delete/127005 Reject -- https://main.php.net/note/reject/127005 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218305) next »