Page 3 of 3

Posted: Wed Apr 12, 2006 5:26 pm
by pickle
Well ya. You're creating the $date variable instead of the $filename variable. If no $filename variable is being instantiated, its certainly not going to print out.

Posted: Wed Apr 12, 2006 5:30 pm
by ozzy
Sould i t look like this?

Code: Select all

<?php
$arrayFiles=glob('*.*');
$date=date ("F d Y H:i:s.", filemtime($filename));
if($date){
  foreach ($date as $filename) {
   echo "$filename <br>";
  }
}
else
  echo"File not found."

?>
If so, it is returning this error:

Code: Select all

Warning: Invalid argument supplied for foreach() in /host/htdocs/vuns/index.php on line 5

Posted: Thu Apr 13, 2006 2:40 am
by Chris Corbyn
ozzy wrote:Sould i t look like this?

Code: Select all

<?php
$arrayFiles=glob('*.*');
$date=date ("F d Y H:i:s.", filemtime($filename));
if($date){
  foreach ($date as $filename) {
   echo "$filename <br>";
  }
}
else
  echo"File not found."

?>
If so, it is returning this error:

Code: Select all

Warning: Invalid argument supplied for foreach() in /host/bluemicro.digibase.ca/htdocs/vuns/index.php on line 5
Come on dude you know you can do a little more reading around ;)

http://www.php.net/foreach

php.net is your friend (and my friend!).

foreach() is a speacial loop. It loops over an array. The basic structure is one of the two possible variations below:

Code: Select all

foreach ($some_array as $value)
{
    //Look at each value in the array and tore it temporarily in $value
}

foreach ($some_array as $key => $value)
{
    //In an array like:
    // $some_array['foo'] = 'bar';
    // Look at each key (foo) and each value (bar)
}
Also... the error messages you are seeing are extremely descriptive and as such should be a clear indication at the very least of which line in your code to check.... then you can refer to the manual at php.net again ;)

As you may have noticed... we don't often just write out code for you... you learn far more struggling through it by yourself :D

Posted: Sun Apr 16, 2006 2:01 pm
by ozzy
I have looked through the foreach manual on php.net.. but i didnt fully understand it.

I also know what the problem is, but requests are of how to reslove them.

Code: Select all

Warning: Invalid argument supplied for foreach() in /host/htdocs/vuns/index.php on line 5

Posted: Sun Apr 16, 2006 2:13 pm
by John Cartwright
you are not passing an array to the foreach().