Here is an example array:
$foo = array(
\'employer\' => array(
\'name\' => \'Foobar Inc\',
\'phone\
/**
* Flatten a multi-dimensional array or a nested object, constructing concatenated keys for
* nested elements.
* @param array or object $array - the array or object to be flattened
* @param array or string $key_path - current parent keys path.
* Pass this parameter as string if you need to set a common prefix for all keys
* @param string $level_separator - keys concatenation glue
* @param array $flat - resulting flattened array (omit this parameter when calling the function)
* @return single-dimensional array with all array keys as concatenated keys of elements'
* paths through the data structure
*/
function flattenArray($array, &$key_path = array(), $level_separator = '.', &$flat = array())
{
if(!is_array($key_path))
{
// sanitize key_path
$key_path = array((string)$key_path);
}
foreach($array as $key => $value)
{
// push current key to path
array_push($key_path, $key);
if(is_array($value) || is_object($value))
{
// next level recursion
$flat = array_merge($flat, flattenArray($value, $key_path, $level_separator, $flat));
}
else
{
// write the value directly
$flat[implode($level_separator, $key_path)] = $value;
}
// remove used key
array_pop($key_path);
}
return $flat;
}