Page 1 of 1
Beginners question
Posted: Wed Oct 08, 2003 3:48 pm
by buffchazen
Can anyone explain what this line of code is doing for me please?
$login = ($request->parameterExists('login')) ? $request->getParameter('login') : '';
Posted: Wed Oct 08, 2003 3:59 pm
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!
Posted: Wed Oct 08, 2003 4:05 pm
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';
}
thanks
Posted: Wed Oct 08, 2003 4:24 pm
by buffchazen
thanks for your help guys. so the ? is like an "if false"?
Posted: Wed Oct 08, 2003 4:32 pm
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;
Posted: Wed Oct 08, 2003 4:38 pm
by buffchazen
got it. thanks guys.
