Help with array
Moderator: General Moderators
-
hesham2012
- Forum Newbie
- Posts: 8
- Joined: Fri Mar 09, 2007 11:34 pm
Help with array
Hello everyone
i have a page which lets the user choose from "select form list/menu" a number of fields that he will fill for example the user is
asked 'how many children you have?'
maybe he has 1 ,2,12 or 20 whatever he choosed the number from list/menu. after he choosed the number he goes to another
page with number of 'inputs text form' as he choosed before. now he will enter his children names i want to be sure he inserted
every name just one time no duplicated names but in the same thime i don't know how many input fields i have, every one has a
different number of children so i think it will be a good idea if i can put all names in an array and use array_unique then count the
two arrays if the numbers are different sure there is a duplicated names
if any one can help me to carry htis out or has a better idea i'll appreciate this thanks
i have a page which lets the user choose from "select form list/menu" a number of fields that he will fill for example the user is
asked 'how many children you have?'
maybe he has 1 ,2,12 or 20 whatever he choosed the number from list/menu. after he choosed the number he goes to another
page with number of 'inputs text form' as he choosed before. now he will enter his children names i want to be sure he inserted
every name just one time no duplicated names but in the same thime i don't know how many input fields i have, every one has a
different number of children so i think it will be a good idea if i can put all names in an array and use array_unique then count the
two arrays if the numbers are different sure there is a duplicated names
if any one can help me to carry htis out or has a better idea i'll appreciate this thanks
Array_unique is not a solution, because it's just gonna remove the duplicate names.
I think what you should do is to check every name if it matches any other names.
you can use preg_match or just ==.
And to do so put your process into a double loop like
I think what you should do is to check every name if it matches any other names.
you can use preg_match or just ==.
And to do so put your process into a double loop like
Code: Select all
while(){
while(){
}
}- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
You could names two twins Joseph and call one by Joe and one by Joey. You can tell them apart by nickname, but professionally, you would write their actual name, not their nickname.ankhmor wrote:I don't think that its alowed to name two of your kids the same name. Is it?
And anyways one will be younger and another one will be older.
-
hesham2012
- Forum Newbie
- Posts: 8
- Joined: Fri Mar 09, 2007 11:34 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Thank you all i did something like this and worked 100%
Post input name L1,L2,L3 ....Code: Select all
<?php
for($i=1;$i<=$_POST[x];$i++)
{
$f=$i+1;
$a=$_POST[("L".$i)];
for($x=$f;$x<=$_POST[x];$x++)
{
$b=$_POST[("L".$x)];
if($a==$b){echo"One or more name is duplicated";}
}
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]