[thelist] stupid PHP question

klute soundres9 at yahoo.com
Thu Jul 7 09:29:51 CDT 2005


I did not realize that PHP could use this syntax (I
know it from Java)

What means is:

the value to be assigned to $row_count equals
count($row) if $row happens to be an array. otherwise,
$row_count equals 0. 

here is another example

x = (y == 3) ? y : 5;

x equals 3 if y equals 3. otherwise, x equals 5.

hope this helps
james

--- Nan Harbison <nan at heritageconcord.org> wrote:

> 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 ! 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the thelist mailing list