|
|
 |
| Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

May 24th, 2004, 03:02 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Location: Coeur d\'Alene, ID, USA.
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
? operator in PHP
http://php.planetmirror.com/manual/e....operators.php
shows the ? operator but I can't seem to find a description of what it means or what it does. Does anyone know?
__________________
An overworked Web Developer who\'s expected to know everything yet given time to study nothing.
|

May 24th, 2004, 03:06 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here's a brief description:
The '?' operator is like a shortcut for the if() function.
This:
if($variable === TRUE) doSomething();
else doSomethingElse();
Is equivalent to this:
($variable === TRUE) ? doSomething() : doSomethingElse();
HTH,
Snib
<><
|

May 24th, 2004, 03:59 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,697
Thanks: 0
Thanked 1 Time in 1 Post
|
|
It's called the ternary operator, and its an expression, if / else if / else are control structures, so technically it isn't just a shortcut for if/else
The manual shows an example like this:
<?php
$first ? $second : $third;
?>
Each of the variables represents a sub expression,
If the value $first subexpression evaluates to TRUE, the code contained in $second subexpression is evaluated if the $first subexpression evaluates as FALSE the $third subexpression is evaluated. Commonly you'll find this in a use that is representable by a simple if/else structure.
if ($foo == TRUE) {
$bar = 1;
} else {
$bar = 0;
}
Is the same thing as saying:
$bar = ($foo == TRUE)? 1 : 0;
You can find it in the PHP manual here:
http://www.php.net/manual/en/language.expressions.php
Regards,
Rich
::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |