List Info

Thread: note 70036 added to function.array-merge-recursive




note 70036 added to function.array-merge-recursive
user name
2006-09-30 19:25:16
<?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  -- h
ttps://master.php.net/note/delete/70036/integrated
Del: useless     -- http
s://master.php.net/note/delete/70036/useless
Del: bad code    -- htt
ps://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     -- http
s://master.php.net/note/delete/70036/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/70036
Reject      -- https://mast
er.php.net/note/reject/70036
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )