Page 1 of 1

Invalid argument supplied for foreach

Posted: Sat May 10, 2008 2:33 pm
by toasty2
I'm reading a directory for HTML files and trying to save them to an array (also with information about like when each file was last modified) so they can later be used in a table.
Here's my array of files:
$FILES:

Code: Select all

Array
(
    [0] => Array
        (
            [name] => example
            [mod] => 1184979992
            [created] => 1197347342
        )
    [1] => Array
        (
            [name] => index
            [mod] => 1208139263
            [created] => 1197347342
        )
    [2] => Array
        (
            [name] => menu
            [mod] => 1208124930
            [created] => 1197347342
        )
)
That information is prepared earlier in the script. Inside a function I try to create a table:

Code: Select all

global $FILES, $NAV;
$ctableHTML = '<table id="contenttable"><tr><td>Name</td><td>Date Created</td><td>Last Modified</td><td></td></tr>';
foreach($FILES as $f) // The line it says the error occurs at
{
  $ctableHTML .= "<tr><td>{$f['name']}</td><td>{$f['created']}</td><td>{$f['mod']}</td><td><a href=\"?a=edit&f={$f['name']}\">edit</a></td></tr>";
}
$ctableHTML .='</table';
 
$PAGE = <<<html
$NAV
$ctableHTML
html;

Re: Invalid argument supplied for foreach

Posted: Sat May 10, 2008 8:04 pm
by yacahuma
And your question is?

Re: Invalid argument supplied for foreach

Posted: Sun May 11, 2008 1:28 am
by toasty2
Why do I get the error with foreach?

Re: Invalid argument supplied for foreach

Posted: Sun May 11, 2008 1:45 am
by nowaydown1
Can you post your full script? It would help us track down your issue.

Re: Invalid argument supplied for foreach

Posted: Sun May 11, 2008 1:13 pm
by toasty2
I figured it out. My array didn't exist before I tried to use it. :|