We help IT Professionals succeed at work.
Get Started

Php, Get different arrays from class

Pedro Chagas
Pedro Chagas asked
Last Modified: 2012-05-12
Hi E's, the code in snippet code show in the browser all folders and all files inside specific folder.
The output is one array with two different keys, directories and files, and the problem is that information comes together.
So, because that I need to separate directories and files, and I need to put that information inside this arrays: array_directories and array_files.
How I do that?

Regards, JC
    $obj = new read_full_dir('../../upload/'); 
        echo "<pre>"; 
         echo "</pre>"; 
class read_full_dir 
  var $dir_tree; 
     class constructor 
  function read_full_dir( $path_to_dir ) 
    $this->read_directory( $path_to_dir ); 
      reads the full directory tree and store it in 
  function read_directory( $directory ) 
    if ( $handle =     @opendir( $directory ) ) 
    while ( false !== ( $file = readdir( $handle ) ) ) 
        if ( $file != ".." && $file != "." ) 
        if( is_dir( $directory.'/'.$file)) 
          $this->dir_tree['directories'][] = $directory.'/'.$file; 
          $this->read_directory( $directory.'/'.$file ); 
          $this->dir_tree['files'][] = $directory.'/'.$file; 
  function getTree(){ 
      return $this->dir_tree; 

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE