View previous topic :: View next topic |
Author |
Message |
Flux -
Joined: 13 Oct 2006 Posts: 48
|
Posted: Sun Apr 22, 2007 6:57 pm Post subject: arrays and strings in a for() {} |
|
|
So let's say I have to make a few directories in succession.
Directory that exists: /files/user/pics/
Directory that ultimately needs to exist: /files/user/pics/oneday/thatevent/thistime/
I have mkdir().
I have the string $subfolder1 = "oneday/thatevent/thistime".
I have the array $subfolder = explode( "/" , $subfolder1).
I want to cause this to happen:
Code: | mkdir("/files/user/pics/oneday");
mkdir("/files/user/pics/oneday/thatevent");
mkdir("/files/user/pics/oneday/thatevent/thistime"); |
I need to find a php script version of, basically, this:
so let's say we have:
Code: | for ($i = 0; $i < count($subfolder); $i++) {
mkdir("/files/user/pics".$sub);
} |
How do I get $sub to equal in the first instance $subfolder[0], then the second $subfolder[0]."/".$subfolder[1] etc. etc. until I reach the final piece of the array and the script stops? Note that I ask with the intent to not have a limit on how many there are in the array/the number of pieces of array are not set in stone/I don't know how many pieces to the array there will be. _________________ My signature is so lame.
I think phpBB forums hates my laptop '.'; |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Mon Apr 23, 2007 4:57 pm Post subject: Re: arrays and strings in a for() {} |
|
|
Code: |
$sub = "/files/user/pics";
for ($i = 0; $i < count($subfolder); $i++) {
$sub = $sub . "/" . $subfolder[$i];
mkdir($sub);
} |
_________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
Flux -
Joined: 13 Oct 2006 Posts: 48
|
Posted: Wed Apr 25, 2007 12:05 am Post subject: |
|
|
smart is me..or not.
Thanks again aprelium. _________________ My signature is so lame.
I think phpBB forums hates my laptop '.'; |
|
Back to top |
|
|
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Wed Apr 25, 2007 12:36 pm Post subject: |
|
|
You should have a look at foreach() instead.
Code: | <?php
$subs = array("./test", "./test/hello", "./test/hello/world");
foreach($subs as $key => $value) {
mkdir($value);
echo "Created: ".$key." - ".$value."<br />";
}
?> |
|
|
Back to top |
|
|
|