Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/146337-problem-with-counting-arrays/
Share on other sites

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.