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



Reply via email to