> -----Original Message----- > From: Timothy J. Luoma [mailto:[EMAIL PROTECTED]] > Sent: 09 March 2002 10:08 > To: PHP Mailing List > Subject: [PHP] need help converting code to more efficient loop > > 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:
<snip> Try this: $ICON_COUNT="0"; foreach (array('SHOW_WAI_ICON', 'SHOW_BOBBY508_ICON', 'SHOW_W3_ICON', 'SHOW_CSS_ICON') as $icon): if ($$icon != "no"): $ICON_COUNT++ ; endif; endforeach; or, slightly less efficient but slightly nearer to your bash example: foreach (explode(' ', 'SHOW_WAI_ICON SHOW_BOBBY508_ICON SHOW_W3_ICON SHOW_CSS_ICON') as $icon): if ($$icon != "no"): $ICON_COUNT++ ; endif; endforeach; 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