RE: [PHP] need help converting code to more efficient loop
| From: | Ford, Mike [LSS] | Date: | Wed, 13 Mar 2002 15:01:56 +0000 |
| Subject: | RE: [PHP] need help converting code to more efficient loop | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-88353@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Timothy J. Luoma [mailto:luomat@peak.org]
> 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: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211