Jump to content

gwtting paths from root of array?


herghost

Recommended Posts

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

 

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
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.