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
taldos
Forum Commoner
Posts: 39 Joined: Mon Aug 23, 2004 8:47 am
Location: Philadelphia
Post
by taldos » Tue Jun 06, 2006 11:31 am
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
daedalus__
DevNet Resident
Posts: 1925 Joined: Thu Feb 09, 2006 4:52 pm
Post
by daedalus__ » Tue Jun 06, 2006 11:37 am
It is a ternary operator.
It's like a shorthand if statement for declaring variables.
$var = condition ? then : else;
(i think)
aerodromoi
Forum Contributor
Posts: 230 Joined: Sun May 07, 2006 5:21 am
Post
by aerodromoi » Tue Jun 06, 2006 11:37 am
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
PrObLeM
Forum Contributor
Posts: 418 Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:
Post
by PrObLeM » Tue Jun 06, 2006 11:37 am
taldos
Forum Commoner
Posts: 39 Joined: Mon Aug 23, 2004 8:47 am
Location: Philadelphia
Post
by taldos » Tue Jun 06, 2006 11:57 am
thx guys.