Re: Help understanding code...
| From: | Baroiller Pierre-Emmanuel | Date: | Fri, 26 Sep 2003 08:49:46 +0000 |
| Subject: | Re: Help understanding code... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-164018@lists.php.net to get a copy of this message | ||
Hi,
It's a "C Like Syntax"
(condition)?true:false;
is like :
if (condition) true
else false
regards.
P.E. Baroiller
"Jeff McKeon" <jmckeon@telaurus.com> a écrit dans le message de
news:B3F5C378E4B6034CA27B15C99E9133CE63EAD4@exch01tc07927.telaurus.net...
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