[thelist] stupid PHP question
David Felton
davidfelton at codemasters.com
Thu Jul 7 09:20:46 CDT 2005
This is what's known as the ternary conditional operator.
$row_count = is_array($row) ? count($row) : 0;
is the short-hand equivalent of:
if(is_array($row)) {
$row_count = count($row);
} else {
$row_count = 0;
}
You'll find a lot more info on it if you Google for "ternary conditional
operator"
-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org]On Behalf Of Nan Harbison
Sent: 07 July 2005 2:43
To: thelist at lists.evolt.org
Subject: [thelist] stupid PHP question
Hello All,
I have this function $array is a two dimensional array being retrieved from
a table):
foreach ($array as $row)
{
$row_count = is_array($row) ? count($row) : 0;
if ($row_count > $max_cols)
{
$max_cols = $row_count;
}
}
What I don't understand is the syntax of this line:
$row_count = is_array($row) ? count($row) : 0;
I have spent hours looking through my PHP books, but can't find it. Can
someone please explain what the question mark is doing? And the count($row)
: 0?
Sorry, I know this is a dumb question.
TIA,
Nan
--
* * Please support the community that supports you. * *
http://evolt.org/help_support_evolt/
For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
**********************************************************************
More information about the thelist
mailing list