RE: [PHP] String compare of 7 text strings

From: Date: Sat, 14 Aug 2004 14:24:03 +0000
Subject: RE: [PHP] String compare of 7 text strings
Groups: php.general 
Request: Send a blank email to php-general+get-193797@lists.php.net to get a copy of this message
-----Original Message----- From: Brent Clements To: php-general@lists.php.net I wanted to see if anyone has an easier way to do this. The end result is this: I need to compare 7 different text strings(which are in an array). They should all be the same, if they are not the same, a message should be outputted saying they weren't. How would one do this outside of using a huge if/then statement? --------------------------- Two approaches come to mind off the top of my head: $values = array_count_values($array); if (count($values)>1): // there's more than one unique value in the array endif; or... $value = $array[0]; for ($i=1; $i<7; ++$i): if ($array[$i]!= $value): // this value doesn't match break; endif; endfor; Cheers! Mike

« previous php.general (#193797) next »