1. Using [] creates a new array element. Hence the error. You can try this piece of code inside the loop
[code] if (strstr ($file, '.jpg')){ $refPictures = & $pictures[]; $refPictures = $file; print $refPictures; } [/code] $refPictures holds a reference to the newly created element of the $pictures array. Therefore, by assigning $file to $refPictures, $file is actually getting assigned to the newly created element of the $pictures array. The same logic applies in the print statement 2. Again, using [] in the var_dump indicates that you are trying to create a new element of the $pictures array. If dumping the contents of the entire array along with their data types and such is what you are trying to achieve, the correct syntax is [code] var_dump($pictures); [/code] > -----Original Message----- > From: Paul Furman [mailto:[EMAIL PROTECTED] > Sent: Friday, February 06, 2004 3:09 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] beginner question about while loops > > > Eric Gorr wrote: > > > >> 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. > > > 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)){ > 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); > } > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php