Skip to content

Instantly share code, notes, and snippets.

@tohokuaiki
Last active November 16, 2016 03:06
Show Gist options
  • Save tohokuaiki/85dd3b0565a7eb50e543843d338997eb to your computer and use it in GitHub Desktop.
Save tohokuaiki/85dd3b0565a7eb50e543843d338997eb to your computer and use it in GitHub Desktop.
配列を再帰的にMergeする。存在するキーだけ上書きし、存在しない場合はoriginを引き継ぐ
<?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