Jump to content

problem with counting arrays


shadiadiph

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.