Skip to content

Instantly share code, notes, and snippets.

@KEINOS
Last active May 29, 2017 21:42
Show Gist options
  • Select an option

  • Save KEINOS/33c53a9a85e0ac7b4e32ae11fbfd38fd to your computer and use it in GitHub Desktop.

Select an option

Save KEINOS/33c53a9a85e0ac7b4e32ae11fbfd38fd to your computer and use it in GitHub Desktop.
PHPで添え字付き多次元配列を結合するための関数
<?php
function fArray_merge($aOld, $aNew)
{
if (is_array($aOld)) {
if (is_array($aNew)) {
foreach ($aNew as $sKey => $mValue) {
if (isset($aOld[$sKey]) && is_array($mValue) && is_array($aOld[$sKey])) {
$aOld[$sKey] = fArray_merge($aOld[$sKey], $mValue);
} else {
$aOld[$sKey] = $mValue;
}
}
}
} elseif (! is_array($aOld) && ( strlen($aOld) == 0 || $aOld == 0 )) {
$aOld = $aNew;
}
return( $aOld );
}
/* 詳細: https://blog.keinos.com/20080913_760 */
/* GIST: https://gist.github.com/KEINOS/33c53a9a85e0ac7b4e32ae11fbfd38fd */
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment