RichieG Posted May 2, 2007 Share Posted May 2, 2007 Hi all... I'm having a little problem understand the syntax for foreach loops, and the PHP manual isn't helping much, as it doesn't seem to be as descriptive as other pages in the manual. foreach ($errmsg as $a) { echo $errmsg[$a] . "<br>\n"; } That's my code. The $errmsg is an array which holds different strings depending on what errors were formulated from the code above it ($errmsg[$errmsgno++] = "Your password was not correct"; is the code for one of those. It's executing the code once, but not echoing the message given. Do I have the foreach wrong, or is the error elsewhere in my code? TIA, Richie G Quote Link to comment https://forums.phpfreaks.com/topic/49665-solved-foreach-loops/ Share on other sites More sharing options...
ToonMariner Posted May 2, 2007 Share Posted May 2, 2007 try this <?php foreach ($errmsg as $key => $val) { echo $key . " = " . $val . "<br>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49665-solved-foreach-loops/#findComment-243497 Share on other sites More sharing options...
RichieG Posted May 2, 2007 Author Share Posted May 2, 2007 That was a quick reply Yes - that works. Thanks a lot. I'm still a little confused over the syntax of the loop, but there we go - as long as it's working! Quote Link to comment https://forums.phpfreaks.com/topic/49665-solved-foreach-loops/#findComment-243504 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.