Help with array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hesham2012
Forum Newbie
Posts: 8
Joined: Fri Mar 09, 2007 11:34 pm

Help with array

Post by hesham2012 »

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
ankhmor
Forum Newbie
Posts: 12
Joined: Fri Jul 13, 2007 4:45 pm

Post by ankhmor »

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

Code: Select all

while(){
while(){

}
}
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

May I suggest a different approach: display just one Input box at a time, with two buttons below it: "Enter Another" and "Finished". It's easier to program and it's easier for the user.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

What if I have two kids named Joe?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

astions wrote:What if I have two kids named Joe?
Poor Joe. Joe is always mistaken for Joe.
ankhmor
Forum Newbie
Posts: 12
Joined: Fri Jul 13, 2007 4:45 pm

Post by ankhmor »

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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

ankhmor wrote:I don't think that its alowed to name two of your kids the same name. Is it?
Why wouldn't it be allowed?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

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.
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.
hesham2012
Forum Newbie
Posts: 8
Joined: Fri Mar 09, 2007 11:34 pm

Post by hesham2012 »

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]
Post Reply