简体   繁体   中英

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.

检查变量的大小写: $itemError / $ItemError

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM