RE: Multiple "if()" statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 29 June 2006 01:03, David Tulloh wrote:


> I'm also going to throw in an elseif for fun, to get this (hopefully)
> improved version: 
> 
> if($row[1] == "none") {
>    print("<tr>");
>    print("<td>$row[0] $row[2]</td>");
>    print("</tr>");
> } elseif($row[1] == $row[2]) {
>    print("<tr>");
>    print("<td>$row[0] $row[2]</td>");
>    print("</tr>");
> } else {
>    print("<tr>");
>    print("<td>$row[0] ($row[1]) $row[2]</td>");
>    print("</tr>");
> }

This still seems overly complex to me -- there are 3 identical occurrences of some items.

When constructing an if() sequence, I think it's always important to isolate the parts that genuinely differ, so my effort would go like this:

    echo "<tr>";
    echo "<td>$row[0] ";
    if ($row[1] != "none" && $row[1] != $row[2]) {
       echo "($row[1]) ";
    }
    echo "$row[2]</td>";
    echo "</tr>";


Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 


To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux