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
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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.