Last active
May 29, 2017 21:42
-
-
Save KEINOS/33c53a9a85e0ac7b4e32ae11fbfd38fd to your computer and use it in GitHub Desktop.
PHPで添え字付き多次元配列を結合するための関数
This file contains hidden or 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 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