Re: checking for duplicate values among five variables

From: Date: Sat, 07 Jul 2007 03:10:18 +0000
Subject: Re: checking for duplicate values among five variables
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-258441@lists.php.net to get a copy of this message
On Fri, 2007-07-06 at 23:03 -0400, Robert Cummings wrote: > On Fri, 2007-07-06 at 21:51 -0500, 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? > > <?php > > $a1 = 1000; > $a2 = 2000; > $a3 = 2000; > $a4 = 4000; > $a5 = 5000; > > $hits = array(); > for( $i = 0; $i < 5; $i++ ) Should be: for( $i = 1; $i <= 5; $i++ ) > { > $hits[${'a'.$i}][] = 'a'.$i; > } > > foreach( $hits as $value => $vars ) > { > if( count( $vars ) > 1 ) > { > echo 'Value: '.$value."\n"; > print_r( $vars ); > } > } > > ?> Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#258441) next »