Re: help with script needed
| From: | Stut | Date: | Tue, 13 Mar 2007 09:10:44 +0000 |
| Subject: | Re: help with script needed | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250398@lists.php.net to get a copy of this message | ||
Richard Lynch wrote:
You could also just use: if (($i % 15) === 0) echo "FooBar"; elseif (($i % 3) === 0) echo "Foo"; elseif (($i % 5) === 0) echo "Bar"; 15 works because 3 and 5 are mutually prime or whatever it's called.Good point, missed that one.
A minimalist might not even bother with the 15 and would skip the 'else' and just do: if (($i % 3) === 0) echo "Foo"; if (($i % 5) === 0) echo "Bar"; echo "\n"; I personally think that's less comprehensible, however, and less maintainable, so I'd rather see a couple more CPU cycles than have code I have to think about to figure out what it does, until it's a proven bottleneck.Except that you're not displaying the actual number when it's not divisible between 3 or 5, so that doesn't meet the spec. Sorry. -Stut