You are here: Re: Help with ? and : « All PHP « IT news, forums, messages
Re: Help with ? and :

Posted by Lars Eighner on 05/10/06 17:43

In our last episode,
<1147270557.730422.186550@u72g2000cwu.googlegroups.com>,
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@larseighner.com 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_

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация