shadiadiph Posted February 22, 2009 Share Posted February 22, 2009 I am beginning to understand php better these days but the one thing that has still got me stumped is $i=0 and i don't really understand is the counting of arrays for example I am been trying to find out the values of the following but I am missing something somewhere? for ($i=0; $i=count($error); $i++) if ($name=="") { $error[$i] ="Name is a required please fill in and submit again."; } if ($email=="") { $error[$i] ="Email is a required please fill in and submit again."; } { echo $error[$i]; } there should be two errors showing here but it is only showing the last one email Quote Link to comment https://forums.phpfreaks.com/topic/146337-problem-with-counting-arrays/ Share on other sites More sharing options...
sasa Posted February 22, 2009 Share Posted February 22, 2009 try if ($name=="") { $error[] ="Name is a required please fill in and submit again."; } if ($email=="") { $error[] ="Email is a required please fill in and submit again."; } for ($i=0; $i<count($error); $i++) { echo $error[$i]; } [/code] Quote Link to comment https://forums.phpfreaks.com/topic/146337-problem-with-counting-arrays/#findComment-768281 Share on other sites More sharing options...
shadiadiph Posted February 22, 2009 Author Share Posted February 22, 2009 mm thank you works fine but can anyone explain this to me for ($i=0; $i<count($error); $i++) I understand that $i=0 $i is set to 0 but i am still a bit confused about $i<count($errors) i seem to be undertsnading that $i is less than the error count?? sorry i really need to understand this is has been bugging me for ages Quote Link to comment https://forums.phpfreaks.com/topic/146337-problem-with-counting-arrays/#findComment-768286 Share on other sites More sharing options...
shadiadiph Posted February 22, 2009 Author Share Posted February 22, 2009 so it is impossible to use if ($name=="") { $error[] ="Name is a required please fill in and submit again."; } if ($email=="") { $error[] ="Email is a required please fill in and submit again."; } for ($i=0; $i<count($error); $i++) { header ("location: ../careers.php?error=$error[$i]"); exit; } sorry this is a mess Quote Link to comment https://forums.phpfreaks.com/topic/146337-problem-with-counting-arrays/#findComment-768290 Share on other sites More sharing options...
sasa Posted February 22, 2009 Share Posted February 22, 2009 no when you 1st time call header('Location: ...') function curent page stop working Quote Link to comment https://forums.phpfreaks.com/topic/146337-problem-with-counting-arrays/#findComment-768557 Share on other sites More sharing options...
shadiadiph Posted February 22, 2009 Author Share Posted February 22, 2009 no it's not impossible or no it's not possible? Quote Link to comment https://forums.phpfreaks.com/topic/146337-problem-with-counting-arrays/#findComment-768746 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.