views:

115

answers:

2

What is a simple mode, in PHP, to remove all the sub arrays of a multidimensional array? What I want is to remove all the sub arrays but the top one...

Thanks, titel

+5  A: 
foreach($array as $k => $a) {
    if (is_array($a)) { unset($array[$k]); }
}

Like this?

Savageman
+2  A: 
function FlattenCallback($Value) { return !is_array($Value); }

$OneDimension = array_filter($MultiDimension, 'FlattenCallback');
sirlancelot