Re: Warning: Invalid argument supplied for foreach()
| From: | Philip Olson | Date: | Sun, 06 Jul 2003 21:18:11 +0000 |
| Subject: | Re: Warning: Invalid argument supplied for foreach() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-154148@lists.php.net to get a copy of this message | ||
On Sun, 6 Jul 2003, arnaud gonzales wrote:
> Hi all,
> I am getting crazy, can't understand what i missed!
> Does anybody know?
>
> $champs = array ("titre_art" => "h3" ,"nom" =>
> "bleu",
> "prenom" => "green", "resume" =>
> "bold");
>
> foreach($champs as $key => $value) {
> echo "<td class='$value'>$row($key))</td>";
> }
It works fine, you are using different code then the above.
In your actual code, make sure you pass in an array that
exists, as currently you are not.
One example reason, the foreach is inside a function and
$champs isn't available in the functions scope (global).
At any rate, before your foreach, var_dump($champs) and
it'll let you know what is up.
Regards,
Philip
p.s. In case $row is an array, you actually mean to write
it as $row[$key], but this is unrelated to the error that
foreach is providing.