This isn't quite true. The strcmp() functions return 0, or false, when
the strings are equal. Thus the ! ensures that the expression evaluates
to true when the strings are equal.
Cheers,
Rob.
On Thu, 2003-09-25 at 15:03, Giz wrote:
> ! (not) reverses the value of the Boolean expression which follows it. All
> Boolean comparisons must evaluate to TRUE or FALSE.
>
> Without the ! the strcmp will proceed to the next block if strcmp returns
> TRUE. With the !, it will proceed to the next block if strcmp returns FALSE
> (ie NOT TRUE).
>
> You could think of it as
>
> If (NOT(TWO STRINGS ARE EQUAL)) THEN {
> DO THIS STUFF
> }
>
>
>
> -----Original Message-----
> From: Jeff McKeon [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 25, 2003 9:55 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: RE: [PHP] Help understanding code...
>
> Thanks for the reply.
>
> What about he use of '!' with the strcmp() command. As I understand it,
> strcmp compairs two strings and returns <0 if str1 is less than str2,
> returns 0 if they are equal and returns >0 if str1 is greater than str2.
> At least that's what the PHP online manual says.
>
> How does the '!' "NOT" switch work with this? Is it saying If str1 and
> str2 are not equal? Or is it saying If str1 and str2 are not compared?
>
> Thanks,
>
> Jeff
>
> > -----Original Message-----
> > From: Jonathan Villa [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, September 25, 2003 12:50 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [PHP] Help understanding code...
> >
> >
> > ! means not, for example $yes != $no
> >
> > Regarding the (xxx) ? x : x;
> > Your assumption is correct
> >
> > I use it alot, but sometimes it's still better to use if/else
> > statements
> >
> > On Thu, 2003-09-25 at 11:47, Jeff McKeon wrote:
> > > I've just picked up a more advanced book on PHP and it has a lot of
> > > example code in it. I understand most of it but some things
> > I'm seeing
> > > I don't understand. Like the following...
> > >
> > > code:
> > >
> > --------------------------------------------------------------
> > ----------
> > > --------
> > >
> > > $couponcode = (! empty($_REQUEST['couponcode'])) ?
> > > $_REQUEST['couponcode'] : NULL;
> > >
> > ----------------------------------------------------------------------
> > > --
> > > --------
> > >
> > > I think this is saying:
> > >
> > > If the global variable couponcode is not empty, then the variable
> > > '$couponcode' is equal to "$_REQUEST['couponcode']"
> > otherwise it gets
> > > a "NULL" value.
> > >
> > > What's throwing me is the use of the "!" and "?" and ":"
> > >
> > > If What I suspect is correct, I've never seen an if-then statement
> > > like this. If it is a replacement for an IF-Then statement
> > then it's
> > > much cleaner and I'd like to use it.
> > >
> > > another one is:
> > >
> > >
> > > code:
> > >
> > --------------------------------------------------------------
> > ----------
> > > --------
> > > IF (!strcmp($operator, '+')) {
> > > $result = $num1 + $num2
> > > }
> > >
> > --------------------------------------------------------------
> > ----------
> > > --------
> > >
> > > I've looked up strcmp() and know it's used to compair two
> > strings. The
> > > $operator variable in the script that this was taken from is set to
> > > either "-", "+", "*" or "/". What I don't understand here
> > is what the
> > > "!" in front of strcmp() means.
> > >
> > > Can anyone break down the code for me and explain the parts?
> > >
> > > thanks,
> > >
> > > Jeff
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
.------------------------------------------------------------.
| 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. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php