Return to Snippet

Revision: 32682
at October 1, 2010 19:35 by CJness


Updated Code
function array_flatten($array, &$new_array = array(), $index = '') 
{
    foreach ($array as $key => $value) 
    {
    	if (!empty($index)) 
    	{
            $key = $index.'_'.$key;
        }
                  
        if (is_array($value)) 
        {
            $new_array = array_flatten($value, $new_array, $key);
        } 
        else 
        {
            $new_array[$key] = $value;
        }        
    }
   
    return $new_array;
}

Revision: 32681
at October 1, 2010 19:28 by CJness


Initial Code
function array_flatten($array, &$new_array = array(), $index = '') 
{
    foreach ($array as $key => $value) 
    {
    	if (!empty($index)) 
    	{
			$key = $index.'_'.$key;
		}
                  
		if (is_array($value)) 
		{
			$new_array = array_flatten($value, $new_array, $key);
		} 
		else 
		{
			$new_array[$key] = $value;
		}        
    }
   
    return $new_array;
}

Initial URL

                                

Initial Description

                                

Initial Title
function array_flatten

Initial Tags
php, array

Initial Language
PHP