inorganik
inorganik

Reputation: 25525

PHP: foreach loop inside a foreach loop for nested arrays

I'm reporting form errors to the user with a nested arrays, because there are different groups to the form and I want to show the errors as such:

        echo "<ul>\n";
        foreach ($errors as $error) {
            if (is_array($error)) {
                echo "Item ".$i." error(s):\n";
                echo "<ul>\n";
                foreach ($error as $itemError) {
                    echo "<li>".$ItemError."</li>\n";
                }
                echo "</ul>\n";
            } else {
                echo "<li>".$error."</li>\n";
            }
            $i++;
        }
        echo "</ul>";

The nested arrays are recognized however the items in the nested arrays don't show up, so I get an empty sub list echoed.

Upvotes: 1

Views: 208

Answers (1)

daiscog
daiscog

Reputation: 12057

Check the case of your variable: $itemError/$ItemError

Upvotes: 4

Related Questions