> -----Original Message-----
> From: Joffrey van Wageningen [mailto:[EMAIL PROTECTED]]
> Sent: 15 February 2002 09:00
>
> i would try:
>
> for($i=01;$i<=50;$i++) {
> if(!empty($content) && $row[$content] == $states[$i])
> $selected = " selected";
> elseif($dstate == $states[$i])
> $selected = " selected";
> else
> $selected = "";
> echo "<option
> value=\"".$states[$i]."\"".$selected.">".$nstates[$i]."</option>";
> }
Well, all the boolean operators use lazy evaluation, so you can safely collapse your
tests into a single one. Also, using the ?: operator, you can turn the whole thing
into a single echo statement:
for($i=01;$i<=50;$i++):
echo "<option value=\"${states[$i]}\"
.((!empty($content) && $row[$content] == $states[$i]) || $dstate ==
$states[$i]
? " selected" : "")
.">${nstates[$i]}</option>";
endfor;
Mind you, I wouldn't particularly claim this to be particularly readable, but it's
about as compact as you can get!
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php