Re: beginner question about while loops
| From: | Paul Furman | Date: | Fri, 06 Feb 2004 20:08:55 +0000 |
| Subject: | Re: beginner question about while loops | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-177041@lists.php.net to get a copy of this message | ||
Eric Gorr wrote:
OK thanks guys, I got the missing curly brace & some other messes. So when assigning values to an array inside a loop, it knows to advance to the next but then if I want to print those out at the same time, it's complaining while ($file = readdir($fh)){the while function knows to just go through those and fills in array numbers accordingly?The while function has nothing to do with it. Using the syntax $array[] simply adds an element onto the _end_ of the array and PHP picks the next logical, numerical index.
if (strstr ($file, '.jpg')){
$pictures[] = $file;
#print $pictures[]; #Fatal error: Cannot use [] for reading
}
var_dump ($pictures[]); #Fatal error: Cannot use [] for reading
}
This one works but complains about Undefined variable: pictures NULL array (but it dumps the contents of $pictures[]:
while ($file = readdir($fh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}
var_dump ($pictures);
}