Page 1 of 1

General syntax question

Posted: Tue Jun 06, 2006 11:31 am
by taldos
the following is a code snippet from a website which I am currently working on. My confusion lies in the use of "?" and ":".

Code: Select all

$phpExt = array('Enroll','Login','ContactUs','sendPW','ProviderNetwork','ResellerEnrollment','ResellerTest');
$extention = (in_array($_GET['pg'],$phpExt)) ? 'php' : 'html';
In this particular case, I'm assuming it means get the file with ".php" extension. if that doesn't work get the file with ".html" extension.

Cheers

Posted: Tue Jun 06, 2006 11:37 am
by daedalus__
It is a ternary operator.

It's like a shorthand if statement for declaring variables.

$var = condition ? then : else;

(i think)

Re: General syntax question

Posted: Tue Jun 06, 2006 11:37 am
by aerodromoi
taldos wrote:the following is a code snippet from a website which I am currently working on. My confusion lies in the use of "?" and ":".

Code: Select all

$phpExt = array('Enroll','Login','ContactUs','sendPW','ProviderNetwork','ResellerEnrollment','ResellerTest');
$extention = (in_array($_GET['pg'],$phpExt)) ? 'php' : 'html';
In this particular case, I'm assuming it means get the file with ".php" extension. if that doesn't work get the file with ".html" extension.

Cheers
That's a short conditional statement.

Code: Select all

expression ? true-statement: false-statement
So in this case, the script will choose the php extension if $_GET['pg'] is in the array,.

aerodromoi

Posted: Tue Jun 06, 2006 11:37 am
by PrObLeM

Posted: Tue Jun 06, 2006 11:57 am
by taldos
thx guys. :)