Beginners question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
buffchazen
Forum Newbie
Posts: 3
Joined: Wed Oct 08, 2003 3:48 pm
Location: mesa, AZ.

Beginners question

Post by buffchazen »

Can anyone explain what this line of code is doing for me please?

$login = ($request->parameterExists('login')) ? $request->getParameter('login') : '';
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

It looks like it's part of a PHP Class object . The ($request->parameterExists('login')) part of it is calling a function to check if something is TRUE or FALSE. If it's TRUE then $login will equal $request->getParameter('login')....... if it's FALSE then $login will equal and empty string ( "" ).

I'm taking a wild guess it's part of some login process!
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

condition ? true : false; is essentially a shorthand if statement.

Code: Select all

$value = ($a == 4 ? 'a is 4' : 'a is not 4');
is the same as

Code: Select all

if ( $a == 4 ) {
    $value = 'a is 4';
} else {
    $value = 'a is not 4';
}
buffchazen
Forum Newbie
Posts: 3
Joined: Wed Oct 08, 2003 3:48 pm
Location: mesa, AZ.

thanks

Post by buffchazen »

thanks for your help guys. so the ? is like an "if false"?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Hope this helps......

<?
$isbigger = ( 10 > 5 ) ? "yes it is bigger" : "no it is smaller";
?>

this will result in $isbigger being "yes it is bigger".

<?
$isbigger = ( 5 > 10 ) ? "yes it is bigger" : "no it is smaller";
?>

this will result in $isbigger being "no it is smaller".

-----------------------------------------

$isItPink = ("pink"== $var) ? true : false;
buffchazen
Forum Newbie
Posts: 3
Joined: Wed Oct 08, 2003 3:48 pm
Location: mesa, AZ.

Post by buffchazen »

got it. thanks guys. :)
Post Reply