note 70036 added to function.array-merge-recursive
| From: | thiago dot mata at yahoo dot com dot br | Date: | Sat, 30 Sep 2006 19:25:16 +0000 |
| Subject: | note 70036 added to function.array-merge-recursive | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117885@lists.php.net to get a copy of this message | ||
<?php
function array_merge_recursive_keep_keys( $arrElement1 , $arrElement2 , $intCount = 0 )
{
$arrNew = array();
$arrElement1Keys = array_keys( $arrElement1 );
$arrElement2Keys = array_keys( $arrElement2 );
$arrDifKeys1 = array_diff( $arrElement1Keys, $arrElement2Keys );
$arrDifKeys2 = array_diff( $arrElement2Keys, $arrElement1Keys );
$arrInter = array_intersect( $arrElement1Keys , $arrElement2Keys );
foreach( $arrDifKeys1 as $strKey1)
{
$arrNew[ $strKey1 ] = $arrElement1[ $strKey1 ];
}
foreach( $arrDifKeys2 as $strKey2)
{
$arrNew[ $strKey2 ] = $arrElement2[ $strKey2 ];
}
foreach( $arrInter as $strInterKey )
{
if( is_array( $arrElement1[ $strInterKey ] ) && is_array( $arrElement2[ $strInterKey ] )
)
{
$intCount++;
$arrNew[ $strInterKey ] = array_merge_recursive_keep_keys( $arrElement1[ $strInterKey ] ,
$arrElement2[ $strInterKey ] , $intCount );
}
elseif( is_array( $arrElement1[ $strInterKey ] ) || is_array( $arrElement2[ $strInterKey ] ) )
{
$arrNew[ $strInterKey ][] = $arrElement1[ $strInterKey ];
$arrNew[ $strInterKey ][] = $arrElement2[ $strInterKey ];
}
else
{
$arrNew[ $strInterKey ] = array();
$arrNew[ $strInterKey ][] = $arrElement1[ $strInterKey ];
$arrNew[ $strInterKey ][] = $arrElement2[ $strInterKey ];
}
}
return $arrNew;
}
?>
----
Server IP: 200.185.126.100
Probable Submitter: 200.190.159.67
----
Manual Page -- http://www.php.net/manual/en/function.array-merge-recursive.php
Edit -- https://master.php.net/note/edit/70036
Del: integrated -- https://master.php.net/note/delete/70036/integrated
Del: useless -- https://master.php.net/note/delete/70036/useless
Del: bad code -- https://master.php.net/note/delete/70036/bad+code
Del: spam -- https://master.php.net/note/delete/70036/spam
Del: non-english -- https://master.php.net/note/delete/70036/non-english
Del: in docs -- https://master.php.net/note/delete/70036/in+docs
Del: other reasons-- https://master.php.net/note/delete/70036
Reject -- https://master.php.net/note/reject/70036
Search -- https://master.php.net/manage/user-notes.php