Search code examples
phpmkdir

PHP - make a bunch of directories 0-z and sub directories 0-z from an array


$path-/home/acname/public_html/storage
$array= (0,1,2,3,4,5,6,7,8,9,a,b, etc.. z);??

using mkdir(); ???

I want to make directories named 0-9 and a-z each with subdirectories in each one 0-z;

eg:

/home/acname/public_html/storage/0/0

all the way to

/home/acname/public_html/storage/9/z

and

/home/acname/public_html/storage/a/0

all the way to

/home/acname/public_html/storage/a/z

continue until ~~~

/home/acname/public_html/storage/z/0

all the way to

/home/acname/public_html/storage/z/z

This will be a one timer I think but far faster than doing it via an ftp client. Figuring this out myself would take longer than the ftp client method! I will learn in the process too.

Thanks in advance!


Solution

  • $names = array_merge(range(0,9), range('a', 'z'));
    $path  = '/home/acname/public_html/storage/';
    
    foreach($names as $cName) {
      mkdir($path . $cName);
      foreach($names as $cName2) {
        mkdir($path . $cName . '/' . $cName2);
      }
    }