|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Creating arrays dynamically with a While loop
After the first 'for' loop it dumps the contents of the first directory into the $files array, and on the second 'for' run it adds the contents of second directory into the $files array. How can I create a unique array name on the second 'for' loop so that I have arrays that contain the contents of each pass? I thought could make it $files1 and $files2 but doing this: $files.$i[] doesn't work.
PHP Code:
|
|
#2
|
||||
|
||||
|
have you thought about multiple dimension arrays?
so you could have a structure like $files['dirname']['filename'] then again, I'm not quite sure what you're trying to accomplish... perhaps some clarification? |
|
#3
|
|||
|
|||
|
you could try nested loops.
Quote:
|
|
#4
|
|||
|
|||
|
creating multiple dimensional array
Quote:
Yeah, say I have two directories, 'docs' and 'images'. Right now I'm getting this info but scanning my directory: PHP Code:
but this produces $myDirs = array('docs','images'); and I want to get to this... $myDirs = array('docs'=> array(), 'images' => array()); How do I get there? Later I'll add to those secondary arrays with the filenames. Make sense? |
|
#5
|
||||
|
||||
|
did you check out some of the comments in the PHP Manual for the readdir listing?
I think Rick has a solution you can use... try the following code the way it is: PHP Code:
|
|
#6
|
||||
|
||||
|
Forgot to mention, refer to Rick's post here: http://ca.php.net/readdir
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Creating arrays dynamically with a While loop |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|