Re: beginner question about while loops

From: Date: Fri, 06 Feb 2004 20:30:39 +0000
Subject: Re: beginner question about while loops
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-177044@lists.php.net to get a copy of this message
----- Original Message ----- From: "Paul Furman" <paul@edgehill.net> > Totally ignorant need for clarification... Should I set up a counter for > loops $integer++ or if I'm going through something, the while function > knows to just go through those and fills in array numbers accordingly? [snip] > while ($file = readdir($dh)){ > if (strstr ($file, '.jpg')){ > $pictures[] = $file; > } With this syntax, you do not need to keep an $integer variable for the array key. When you use $array[] = "something", it just assigns that value to the next available numeric key. while ($file = readdir($dh)){ if (strstr ($file, '.jpg')){ $pictures[$int++] = $file; } Would also be correct, if you wanted to keep the count yourself. You could also use array_push(). Just make sure $pictures is defined as an array before you try to push a value onto it (even using the method you have now), otherwise you'll get a warning. ---John Holmes...

« previous php.general (#177044) next »