Last active
November 16, 2016 03:06
-
-
Save tohokuaiki/85dd3b0565a7eb50e543843d338997eb to your computer and use it in GitHub Desktop.
配列を再帰的にMergeする。存在するキーだけ上書きし、存在しない場合はoriginを引き継ぐ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function array_merge_recursive(&$origin, $extend) | |
{ | |
foreach ($extend as $e_key=>$e_value){ | |
if (!array_key_exists($e_key, $origin)){ | |
$origin[$e_key] = $e_value; | |
} | |
else { | |
if (!is_array($e_value)){ | |
$origin[$e_key] = $e_value; | |
} | |
else { | |
self::array_merge_recursive($origin[$e_key], $e_value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment