Login   Register  
PHP Classes
elePHPant
Icontem

File: array_merge_deep.inc.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jonas Eriksson  >  BowML  >  array_merge_deep.inc.php  >  Download  
File: array_merge_deep.inc.php
Role: Auxiliary script
Content type: text/plain
Description: Improved array functions
Class: BowML
Parse and create HTML or other markup documents
Author: By
Last change:
Date: 9 years ago
Size: 1,019 bytes
 

Contents

Class file image Download
<?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, -1PREG_SPLIT_NO_EMPTY);
}

?>