TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Call what is to print from the array ? (http://www.talkphp.com/general/4119-call-what-print-array.html)

Peuplarchie 04-09-2009 07:05 PM

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 !

xenon 04-09-2009 08:13 PM

PHP Code:

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

That would not work in PHP (at least not yet). What you really want to do is:

PHP Code:

$dirs_list recur_dir('Art');

print_r($dirs_list[1]['name']); 


Kalle 04-09-2009 08:17 PM

PHP does not support function dereferencing (func()['key']), so you need to do what Xenon suggested :)


All times are GMT. The time now is 04:21 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0