Re: comparisons

From: Date: Sun, 11 Feb 2001 20:13:54 +0000
Subject: Re: comparisons
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39139@lists.php.net to get a copy of this message
That was the solution. It worked like a charm. $cmpresult = strcmp($pick1,$pick2); if $cmpresult == 0) { my code; } Can I also write that like the following? if (strcmp($pick1,$pick2) == 0) { perform some action; } Will that work? Curtis ----- Original Message ----- From: "Phil Driscoll" <phil@dialsolutions.co.uk> To: "Curtis Maurand" <curtis@canon.maurand.com>; <php-general@lists.php.net> Sent: Sunday, February 11, 2001 2:34 PM Subject: Re: [PHP] comparisons > In spite of yor best efforts here, PHP converts the string values to numbers (because the strings look like numbers) before doing the comparison. > > Force a string comparison by using strcmp and everything will work fine - remember that strcmp returns true if the strings are not equal and false if equal. > > Cheers > > ________________ Reply Header ________________ > Subject: [PHP] comparisons > Author: "Curtis Maurand" <curtis@canon.maurand.com> > Date: Sun, 11 Feb 2001 18:47:31 +0000 > > Hello, > I'm having a rather strange problem. I'm trying to compare two values. "01" and "1". The variables names that they are submitted under are pick1 and pick2. i use the following code > > $mypick1 = strval($pick1); > $mypick2 = strval($pick2); > > I then perform the following comparison: > > if ($mypick1 == $mypick2) > { > $error = 1; > $errorstring[1] = "Your first pick and second pick are the same."; > } > > However, I get the error that they are equal. > > If I call the comparison as foloows: > > if(strval($mypick1) == strval($mypick2) > { > $error = 1; > $errorstring[1] = "Your first pick and second pick are the same."; > } > > I still get the error. Anyone have any ideas? These two valuse mustbe evaluated as different. > > Thanks in advance > Curtis > > >

« previous php.general (#39139) next »