RE: [PHP] String compare of 7 text strings
-Original Message- From: Brent Clements To: [EMAIL PROTECTED] 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; $i7; ++$i): if ($array[$i]!= $value): // this value doesn't match break; endif; endfor; Cheers! Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String compare of 7 text strings
if ( count ( array_unique ( $array ) ) == 1 ) { // all fields have the same value } we could post solution to this problem for ever... - Hannes On Sat, 14 Aug 2004 15:24:03 +0100 [EMAIL PROTECTED] (Mike Ford) wrote: -Original Message- From: Brent Clements To: [EMAIL PROTECTED] 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; $i7; ++$i): if ($array[$i]!= $value): // this value doesn't match break; endif; endfor; Cheers! Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String compare of 7 text strings
* Ed Lazor wrote : Nice solution =) My thoughts exatly, :D -- Kim Steinhaug - There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. - www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String compare of 7 text strings
On Saturday 14 August 2004 23:12, Hannes Magnusson wrote: if ( count ( array_unique ( $array ) ) == 1 ) { // all fields have the same value } we could post solution to this problem for ever... Indeed: if (count(array_flip($doo)) 1) { // not same } -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* One difference between a man and a machine is that a machine is quiet when well oiled. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String compare of 7 text strings
if ( count ( array_diff ( $array, array ( $array[0] ) ) 0 ) { // not same } On Sun, 15 Aug 2004 00:24:30 +0800 [EMAIL PROTECTED] (Jason Wong) wrote: On Saturday 14 August 2004 23:12, Hannes Magnusson wrote: if ( count ( array_unique ( $array ) ) == 1 ) { // all fields have the same value } we could post solution to this problem for ever... Indeed: if (count(array_flip($doo)) 1) { // not same } -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* One difference between a man and a machine is that a machine is quiet when well oiled. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String compare of 7 text strings
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? Thanks, Brent
Re: [PHP] String compare of 7 text strings
Let me rephase my question in my previous email: I'd like to compare 7 strings(which are in an array). Each string should be the same, if they are not, a message should be outputted. How would one do this outside of using a huge if/then statement? Thanks, Brent - Original Message - From: Brent Clements [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, August 13, 2004 9:07 PM Subject: [PHP] String compare of 7 text strings 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? Thanks, Brent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String compare of 7 text strings
sort ( $array ); if ( $array[ 0 ] !== $array[ count ( $array )-1 ] ) { // Not all fields in the array are the same... } On Fri, 13 Aug 2004 21:10:50 -0500 [EMAIL PROTECTED] (Brent Clements) wrote: Let me rephase my question in my previous email: I'd like to compare 7 strings(which are in an array). Each string should be the same, if they are not, a message should be outputted. How would one do this outside of using a huge if/then statement? Thanks, Brent - Original Message - From: Brent Clements [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, August 13, 2004 9:07 PM Subject: [PHP] String compare of 7 text strings 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? Thanks, Brent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String compare of 7 text strings
Nice solution =) -Original Message- sort ( $array ); if ( $array[ 0 ] !== $array[ count ( $array )-1 ] ) { // Not all fields in the array are the same... } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php