note 111707 added to function.array-intersect-assoc

From: Date: Tue, 19 Mar 2013 20:41:18 +0000
Subject: note 111707 added to function.array-intersect-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-194123@lists.php.net to get a copy of this message
Another implementation of array_intersect_recursive. <?php /** * @author Gajus Kuizinas <g.kuizinas@anuary.com> * @version 1.0.0 (2013 03 19) */ function array_intersect_recursive (array $arr1, array $arr2) { $return = []; $common_keys = array_intersect(array_keys($arr1), array_keys($arr2)); foreach ($common_keys as $key) { if (is_array($arr1[$key]) && is_array($arr2[$key])) { $intersection = array_intersect_recursive ($arr1[$key], $arr2[$key]); if ($intersection) { $return[$key] = $intersection; } } else if ($arr1[$key] === $arr2[$key]) { $return[$key] = $arr1[$key]; } } if (func_num_args() > 2) { $arguments = func_get_args(); array_splice($arguments, 0, 2, [$return]); $return = call_user_func_array('ay\array_intersect_recursive', $arguments); } return $return; } ?> If you are looking at this in 2020, you may seek for an updated version either at https://github.com/gajus/ay-framework or https://gist.github.com/gajus/ef658f04adaec16129a4. ---- Server IP: 69.147.83.199 Probable Submitter: 91.85.156.201 ---- Manual Page -- http://php.net/manual/en/function.array-intersect-assoc.php Edit -- https://master.php.net/note/edit/111707 Del: integrated -- https://master.php.net/note/delete/111707/integrated Del: useless -- https://master.php.net/note/delete/111707/useless Del: bad code -- https://master.php.net/note/delete/111707/bad+code Del: spam -- https://master.php.net/note/delete/111707/spam Del: non-english -- https://master.php.net/note/delete/111707/non-english Del: in docs -- https://master.php.net/note/delete/111707/in+docs Del: other reasons-- https://master.php.net/note/delete/111707 Reject -- https://master.php.net/note/reject/111707 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194123) next »