Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 23rd, 2004, 11:46 AM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Help - Newbie

Just started learning PHP...

looking at some code with statement:

$_SESSION[user][id] = $_POST[login_email] ? $_POST[login_email]: $_SESSION[user][id];

need to understand what this statement does
where can I find info on the operators ? :

Thanks , did not find info in my Beginning PHP4 book
 
Old September 23rd, 2004, 12:34 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

http://us4.php.net/manual/en/language.expressions.php

Basically, this is what this line is doing:

if($_POST[login_email])$_SESSION[user][id] = $_POST[login_email];

HTH,

-Snib <><
http://www.snibworks.com
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)
 
Old September 24th, 2004, 09:28 AM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks
most helpful

 
Old September 26th, 2004, 07:58 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

That's called the ternary operator, it's an expression. You can find it in the PHP manual here:
http://www.php.net/manual/en/language.expressions.php

What happens is there are three subexpressions within the expression

$first? $second : $third;

The $first evaluates to a simple boolean. If it's true, the second subexpression is evaluated, which is the $second variable in the above example. If the $first subexpression evaluates to false, the third subexpression is evaluated.

Often times this can be represented in an identical if/else chain.

The ternary expression:
$foo = ($_POST['field'])? true : false;

is the same as this if/else chain:
if ($_POST['field'])
{
    $foo = true;
}
else
{
    $foo = false;
}

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail





Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help the newbie!! shelly.aix Visual Basic 2008 Essentials 2 December 16th, 2008 07:35 AM
Newbie help... mkruger XSLT 7 October 24th, 2007 02:33 AM
Newbie here jmac731976 HTML Code Clinic 13 August 29th, 2007 03:54 PM
Newbie please help indyanguy XSLT 1 September 2nd, 2005 09:18 AM
Newbie Help! TheShadow Javascript 1 March 21st, 2005 03:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.