Jump to content

[WARNING! Only a Super Genius can solve this] Array with unique values?


onedumbcoder

Recommended Posts

all the values are unique and all the values are digits

is there a way to check that is all values are unique and there is no duplicate??  :'(

 

Ummm, so if you know for sure that the values are unique, why do you need to check to see if they are?

 

And there is a built in function to do this, take a look at the link I sent you.

$unique = true;
foreach ($array as $i => $elem) {
foreach ($array as $j => $elem2) {
	if ($i != $j && $elem === $elem2) {
		$unique = false;
		break 2;
	}
}
}

 

$unique = count(array_unique($array)) == count($array);

 

Plenty of ways. I'm a super genius :)

Edit: So is Maq

If you explain exactly what you are trying to do, maybe we can suggest the best approach.  Since you ignored our previous suggestions it seems we're guessing until then.

 

I FORGOT TO ADD THIS: that all the values are unique and all the values are digits

 

Not sure what the point of this is then?

I am creating a game, where to user has 10 seconds to enter 10 numbers. The challenge is that the numbers can not be the same and that the values entered are numbers and nothing else.

 

so what gets send to the server is an array.

 

 

 

 

 

 

 

alright but when i try preg_match_array, my page stops working

 

No one suggested that, in fact, that's not even a native method.  We're trying to help you and you're doing the complete opposite.  Until you're willing to cooperate and listen, you're wasting everyones' time.

alright but when i try preg_match_array, my page stops working

 

No one suggested that, in fact, that's not even a native method.  We're trying to help you and you're doing the complete opposite.  Until you're willing to cooperate and listen, you're wasting everyones' time.

 

Agreed. I'll come back to the thread once he tries the suggested approaches.

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.