On Saturday 09 March 2002 18:08, Timothy J. Luoma wrote: > 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.
$doo = array("SHOW_CSS_ICON", "SHOW_W3_ICON"); foreach($doo as $dah) { if (${$dah} != "no") { $ICON_COUNT++; } } *** Untested, use with caution! *** -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* Don't put off for tomorrow what you can do today because if you enjoy it today, you can do it again tomorrow. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php