Re: Help with ? and :
- From: Lars Eighner <usenet@xxxxxxxxxxxxxxx>
- Date: Wed, 10 May 2006 09:43:33 -0500
In our last episode,
<1147270557.730422.186550@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
the lovely and talented kenoli
broadcast on alt.php:
Can someone help me interpret this snippet?
printf("<p>The two arrays are %sidentical.</p>\n", $arr1 === $arr2 ? ''
: 'not ');
It is easy to see what it does. It compares two arrays and inserts
either a space or a "not" space in the template string.
The parts I don't understand are the "?" and the ":". I can find no
documentation anywhere of the "?" and the ":".
This is a conditional operator, found in C, shell programming, perl, etc.
stuffa ? stuffb : stuffc
stuffa is evaluated (that may mean being executed)
if that returns a true value stuffb is done, but if the returned value is
false, stuffc is done.
In other words:
stuffa ? stuffb : stuffc
is a way of writing
if stuffa then stuffb else stuffc (punctuated according to your favorite
language)
I have had trouble generally getting good documentation on printf() and
sprintf().
You will often get better clues reading perl or C documentation where these
kinds of things come from.
--
Lars Eighner usenet@xxxxxxxxxxxxxxx http://www.larseighner.com/
War on Terrorism: Bad News from the Sanity Front
"Tactical nuclear capabilities should be used against the bin Laden
camps in the desert of Afghanistan." -Thomas Woodrow,_Washington Times_
.
- Follow-Ups:
- Re: Help with ? and :
- From: kenoli
- Re: Help with ? and :
- References:
- Help with ? and :
- From: kenoli
- Help with ? and :
- Prev by Date: Re: Email is blank to a .net address works fine for .com
- Next by Date: Just not getting it--need help with Generate Report function
- Previous by thread: Help with ? and :
- Next by thread: Re: Help with ? and :
- Index(es):