Web Analytics Made Easy -
StatCounter Call what is to print from the array ? - CodingForum

Announcement

Collapse
No announcement yet.

Call what is to print from the array ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Call what is to print from the array ?

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

  • #2
    you mean something like that:
    PHP Code:
    <?PHP
       
    echo '<pre>';
       
    $arr=recur_dir('Art');
       
    print_r($arr[1]['name']);
       echo 
    '</pre>';
    ?>
    :. -= | Eran | =- .:
    __________________

    Comment

    Working...
    X