Jump to content

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


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.

Alright I give up, I just spend the last 4 hours trying to figure how how to execute java code in php, not only couldn't i do it I had no luck googling it either.

 

Can someone please suggest another way?

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.