herghost Posted January 19, 2012 Share Posted January 19, 2012 Hi all, How do I get the following paths from the array separately in a foreach loop? level.dat level.dat_old session.lock uid.data If I use foreach($outer_dir as $key=>$val) [code] then I get a warning because its returning the folder as 'Array'. The files still upload, as well as a single file called Array. Can i just strip these from the foreach? [code] Array ( [data] => Array ( ) [level.dat] => level.dat [level.dat_old] => level.dat_old [players] => Array ( [herghost.dat] => herghost.dat ) [region] => Array ( [r.-1.0.mcr] => r.-1.0.mcr [r.0.0.mcr] => r.0.0.mcr ) [session.lock] => session.lock [uid.dat] => uid.dat ) herghost.dat Many thanks from a confused user Link to comment https://forums.phpfreaks.com/topic/255389-gwtting-paths-from-root-of-array/ Share on other sites More sharing options...
Andy-H Posted January 19, 2012 Share Posted January 19, 2012 foreach( $outer_dir AS $key => $dir ) { if ( is_array($dir) ) continue; // this will skip past players and region ( and anything else that is an array (or multi-dimensional array) // do something } if you want to get the data from players and region, foreach( $outer_dir AS $key => $dir ) { if ( is_array($dir) ) { foreach( $dir AS $k => $inner_dir ) { // do something } } // do something } Link to comment https://forums.phpfreaks.com/topic/255389-gwtting-paths-from-root-of-array/#findComment-1309417 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.