madrazel Posted June 2, 2007 Share Posted June 2, 2007 example: Array ( [0] => Array ( [0] => /styles/site.css [1] => /styles/mirror.css ) [1] => Array ( [0] => /styles/print.css ) ) i want it to be: Array ( [0] => /styles/site.css [1] => /styles/mirror.css [2] => /styles/print.css ) is there a build-in function for this ? Quote Link to comment Share on other sites More sharing options...
chigley Posted June 2, 2007 Share Posted June 2, 2007 Not that I know of. <?php $array = array(array("/styles/site.css", "/styles/mirror.css"), array("/styles/print.css")); $newarray = array(); foreach($array as $key => $value) { foreach($value as $key2 => $value2) { $newarray[] = $value2; } } ?> I think that would work... Quote Link to comment Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 i JUST made this... enjoy :-) <?php function array_flatten($array){ $out=array(); foreach($array as $k=>$v){ if(is_array($array[$k])){ $out=array_merge($out,array_flatten($array[$k])); }else{ $out[]=$v; } } return $out; } $array[]=array('test','test2'); $array[]='test5'; $array[][]='test3'; $array[][][]='test4'; print_r(array_flatten($array)); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.