Re: checking for duplicate values among five variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 9:51 PM -0500 7/6/07, Kenn Murrah wrote:
Can anyone help me with a way to determine of two or more variables have the same value? For instance,

$a1 = 1000
$a2 = 2000
$a3 = 2000
$a4 = 4000
$a5 = 5000

I want check these five variables and determine whether, as in this case, two or more of the variables have the same value.

Any suggestions how I can do this?

Thanks in advance.

kenn

kenn:

You could use an array.

$a = array(1000, 2000, 2000, 4000, 5000);

$num_before = count($a);

$num_after = count(array_unique($a));

If two, or more, variables have the same value, variables $num_before and $num_after will be different.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux