Jump to content

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


onedumbcoder

Recommended Posts

:facepalm:

 

I don't want to sound demeaning, but looking at your topics, maybe you should reconsider your hobby/career choice? Or maybe you should just stop for a while and take a look at what you're doing. You are failing at really elementary logic all the time.

 

Before someone says I can't say that, I'm saying this as Daniel, not as PHP Freaks admin.

:facepalm:

 

I don't want to sound demeaning, but looking at your topics, maybe you should reconsider your hobby/career choice? Or maybe you should just stop for a while and take a look at what you're doing. You are failing at really elementary logic all the time.

 

Before someone says I can't say that, I'm saying this as Daniel, not as PHP Freaks admin.

 

ouch

:facepalm:

 

I don't want to sound demeaning, but looking at your topics, maybe you should reconsider your hobby/career choice? Or maybe you should just stop for a while and take a look at what you're doing. You are failing at really elementary logic all the time.

 

Before someone says I can't say that, I'm saying this as Daniel, not as PHP Freaks admin.

 

Are u talking about preg_match? I know its failing, that is why i have been trying to solve. Please reads the question before.

using exactly what garethp suggested but in a function...

 

 

function is_unique($array){
    return (count(array_unique($array)) == count($array))?true:false;
}

//FIRST ARRAY - NOT UNIQUE
$arr1[]=123;
$arr1[]=123;

//SECOND ARRAY - UNIQUE
$arr2[]=1;
$arr2[]=2;

//CHECK IF arr1 IS UNIQUE
if(is_unique($arr1)){
    echo "arr1 IS UNIQUE!<BR>\n";
}else{
    echo "arr1 IS NOT UNIQUE!<BR>\n";
}

//CHECK IF arr2 IS UNIQUE
if(is_unique($arr2)){
    echo "arr2 IS UNIQUE!<BR>\n";
}else{
    echo "arr2 IS NOT UNIQUE!<BR>\n";
}

 

This should output:

 

arr1 IS NOT UNIQUE!

arr2 IS UNIQUE!

 

 

using exactly what garethp suggested but in a function...

 

 

function is_unique($array){
    return (count(array_unique($array)) == count($array))?true:false;
}

//FIRST ARRAY - NOT UNIQUE
$arr1[]=123;
$arr1[]=123;

//SECOND ARRAY - UNIQUE
$arr2[]=1;
$arr2[]=2;

//CHECK IF arr1 IS UNIQUE
if(is_unique($arr1)){
    echo "arr1 IS UNIQUE!<BR>\n";
}else{
    echo "arr1 IS NOT UNIQUE!<BR>\n";
}

//CHECK IF arr2 IS UNIQUE
if(is_unique($arr2)){
    echo "arr2 IS UNIQUE!<BR>\n";
}else{
    echo "arr2 IS NOT UNIQUE!<BR>\n";
}

 

This should output:

 

arr1 IS NOT UNIQUE!

arr2 IS UNIQUE!

 

 

 

Thanks, but this wasn't my code. In fact, if it were me, I would have looped through the whole array to check for the value. But now I know about this function, so I'd use this in the future. I actually have to give the credit to Daniel0 on Page 1

honestly guys.. I think hes acting retarded on purpose.. so just don't reply to this post.. delete the topic.. and ban this kid..

 

i agree, im new to php but i dont go around acting dumb on purpose. hes got quite alot of replies and yet he has not solved it, usually 1-3 replies do the trick.

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.