TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-09-2009, 07:05 PM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application 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 !
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 04-09-2009, 08:13 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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']); 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
Peuplarchie (04-09-2009)
Old 04-09-2009, 08:17 PM   #3 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

PHP does not support function dereferencing (func()['key']), so you need to do what Xenon suggested :)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to search array benton General 3 03-29-2009 12:31 AM
array fundamentals allworknoplay Absolute Beginners 6 03-01-2009 09:11 PM
Array mess Killswitch Absolute Beginners 4 12-14-2008 07:35 AM
PHP Script to print nested array sunilbhatia79 Script Giveaway 2 11-16-2007 06:43 PM
Part 1: Getting Started with Array Functions Wildhoney Absolute Beginners 6 10-01-2007 10:53 AM


All times are GMT. The time now is 05:50 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design