Can anyone explain what this line of code is doing for me please?
$login = ($request->parameterExists('login')) ? $request->getParameter('login') : '';
Beginners question
Moderator: General Moderators
-
buffchazen
- Forum Newbie
- Posts: 3
- Joined: Wed Oct 08, 2003 3:48 pm
- Location: mesa, AZ.
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!
I'm taking a wild guess it's part of some login process!
condition ? true : false; is essentially a shorthand if statement.
is the same as
Code: Select all
$value = ($a == 4 ? 'a is 4' : 'a is not 4');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
thanks for your help guys. so the ? is like an "if false"?
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;
<?
$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.