Jump to content

Call what is to print from the array ?


Peuplarchie

Recommended Posts

Good day to you all,

            the following code read a directory recurrently and put the files and folders in an array and I print the array.

         

            I wonder if there is a way to choose which part of the array to print

 

Ex :    print_r(recur_dir('Art')['level' = 1]['name']);

 

Here is my code




<?php

session_start(); 
$dir = "Art/";
   function recur_dir($dir)
   {
       $dirlist = opendir($dir);
       while ($file = readdir ($dirlist))
       {
           if ($file != '.' && $file != '..')
           {
               $newpath = $dir.'/'.$file;
               $level = explode('/',$newpath);
               if (is_dir($newpath))
               {
                   $mod_array[] = array(
                           'level'=>count($level)-1,
                           'path'=>$newpath,
					   'folder'=>$dir,      
                           'name'=>end($level),
                           'kind'=>'dir',
                           'mod_time'=>date ("D F dS Y H:i:s A ", filemtime($newpath)),
                           'content'=>recur_dir($newpath) );
               }else{ 
                   $mod_array[] = array(
                           'level'=>count($level)-1,
                           'path'=>$newpath,
					   'folder'=>$dir,   
                           'name'=>end($level),
                           'kind'=>'file',
                           'mod_time'=>date ("D F dS Y H:i:s A ", filemtime($newpath)),
                           'size'=>filesize($newpath) );
       }
   

           }
       }
       closedir($dirlist);
   $_SESSION['listimages']=$mod_array; 
       return $mod_array;

   }
   

?>
<html>
<head></head>
<body>



<?PHP
   echo '<pre>';
   print_r(recur_dir('Art'));
   echo '</pre>';
?>


</body>
</html>

 

 

Thanks !

Link to comment
https://forums.phpfreaks.com/topic/153373-call-what-is-to-print-from-the-array/
Share on other sites

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.