<?php
/**
* @return array
* @param Array1 $pArr1
* @param Array2 $pArr2
* @desc Merges two arrays and return the merged array
*/
function array_merge_deep( $pArr1, $pArr2 )
{
$tArr2 =& $pArr2;
if(is_null($pArr2))
{
$tArr2 = array();
}
$tArr = array();
foreach( $pArr1 as $iKey1 => $iValue1 )
{
if ( is_null( $tArr2[ $iKey1 ] ))
$tArr[ $iKey1 ] = $iValue1;
else
{
if ( is_array( $iValue1 )) // require that that key always points to an array
$tArr[ $iKey1 ] = array_merge_deep( $iValue1, $tArr2[ $iKey1 ] );
else
$tArr[ $iKey1 ] = $tArr2[ $iKey1 ];
}
}
foreach ( $tArr2 as $iKey2 => $iValue2 )
{
if ( is_null( $pArr1[ $iKey2 ] ))
$tArr[ $iKey2 ] = $iValue2;
}
return $tArr;
}
function array_key_at_value($pArr, $pValue)
{
foreach($pArr as $iKey => $iValue)
{
if($iValue == $pValue)
return $iKey;
}
}
function stringToArray($pString)
{
return preg_split('//', $pString, -1, PREG_SPLIT_NO_EMPTY);
}
?>
|