need help converting code to more efficient loop
| From: | Timothy J. Luoma | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | need help converting code to more efficient loop | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-87863@lists.php.net to get a copy of this message | ||
Hello! I am trying to reduce the size of the code below, which I believe
can be simplified.
I checked the 'for' entry in the manual as well as googling for some
similar code, but did not have any luck.
Here is what I have:
$ICON_COUNT="0";
if ($SHOW_WAI_ICON != "no")
{
$ICON_COUNT++ ;
}
if ($SHOW_BOBBY508_ICON != "no")
{
$ICON_COUNT++ ;
}
if ($SHOW_W3_ICON != "no")
{
$ICON_COUNT++ ;
}
if ($SHOW_CSS_ICON != "no")
{
$ICON_COUNT++ ;
}
Now I would like to make that a 'for' loop, but I'm not sure how to do it
in PHP.
In case it is not clear what I am trying to do, this is what I would do if
PHP syntax were like bash:
variables="SHOW_CSS_ICON SHOW_W3_ICON SHOW_BOBBY508_ICON SHOW_WAI_ICON"
for i in $variables
do
if [ "$i" != "no" ]
then
#increment icon_count here
fi
done
I'm just not sure about the nested syntax in PHP.
Thanks for any help
TjL
--
Site: www.tntluoma.com mailto:luomat@peak.org
Info: Apache/1.3.19 (Unix) with PHP/4.0.6