Hello,
You folks have been lovely to me over the years. I’m so glad that there is a beginners area. I have tried using a certain chat site and I have found that other participants just expect your code from day one to be expert standard. Some people don’t learn like that. My learning style is 1. Write code, get it to function how I intended. 2. Get to grips with syntax and the language. 3. Improve technique once I have the confidence to write code and use PHP more widely. That might not be everybody’s way but it’s my way of learning. Me and my bestie are both studying PHP together and neither of us are the best readers. The PHP Manual is confusing to say the least (at our level).
I have a sneeky suspicion that the above won’t be needed in this forum where people have been lovely.
My project
I have set myself a project of using a basic array of over 30 names and my goal is to create each one of them a) their own directory b) copy an index.php webpage into it that uses the directory name (equal to their first name stored in the array) to say hello to them.
My effort
I have read up on creating directories and also found a handy tip to use dir to ensure that the directory is created where intended. I’ve discovered that permissions are equivalent to chmod. That’s awesome. I’m using a shared website hosting environment. I successfully created a directory using my script and then I got to looking at how the foreach loop would be constructed.
In the answers section for this question Stack Overflow I saw the following that confused me as it was not obvious what in the code was a placeholder and, if they are, what each placeholder would be for. For example, i’m not using an associative array so there is no key value pair:
foreach($folders as $folder)
{
if (!file_exists($folder)) {
mkdir($folder, 0777, true);
}
}
// The following is my work....
<?php
$newStudents = array("Caroline", "David", "Johnny", "Finley", "Skye", "Abigail",
"Jessica", "Toby", "Polly", "Charley", "Gizmo", "Mal", "Killian", "Joseph", "Maria", "Marie", "Tara", "Timothy", "Sebastion", "Paul", "Katherine", "Catherine", "Kate", "Joe", "Charles", "Charlie", "Tom", "Thomas", "Laura", "Stacey", "Melanie", "Jennie", "Jenny", "Stuart", "Steve", "Steven", "Stephen");
foreach ($newStudents as &$eachStudentInArray) {
mkdir(__DIR__ . /student/$eachStudentInArray/, 0755, true);
?>
Thanks and Kind Regards,
bgareth.