Re: help with script needed

From: Date: Wed, 07 Mar 2007 21:26:20 +0000
Subject: Re: help with script needed
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-250039@lists.php.net to get a copy of this message
Are you only using 3 and 5? just echo 3 and 5 instead of Foo and Bar. and for both, just have a 3rd condition including both ... if (($i%3 ==0) && ($i%5 == 0)) echo both or foobar...... does this help? Jake ----- Original Message ----- From: "Bruce Gilbert" <webguync@gmail.com> To: "Martin Marques" <martin@bugs.unl.edu.ar> Cc: "Tijnema !" <tijnema@gmail.com>; "PHP-General" <php-general@lists.php.net> Sent: Wednesday, March 07, 2007 4:00 PM Subject: Re: [PHP] help with script needed
Thanks for the responses so far. This is what I have come up with [php] <?php for( $i=1; $i<=100; $i++ ) { echo $i; echo "<br>"; if ($i%3 == 0) echo "Foo "; elseif ($i%5 == 0) echo "Bar"; } ?> [/php] and the results can be seen here http://www.inspired-evolution.com/image_test/numbers_output.php I actually want the Foo and Bar to replace the numbers they are dereivatives of and not appear below as they are now, and I also need to add a third condition for "FooBar" which would be for numbers that are both divisible by 3 and 5. thanks On 3/7/07, Martin Marques <martin@bugs.unl.edu.ar> wrote:
Tijnema ! escribió:
On 3/7/07, Bruce Gilbert <webguync@gmail.com> wrote:
I just need to add code to print something different, say "foo" if the output is a multiple of 5 or 10 for example. How do I go about doing this?
I've seen that question a lot, what i use is fairly simple if( intval($number / $multiple) == ($number / $multiple ) ) try that
Very bad solution. Try the % operator: if($number % $multiple == 0) http://www.php.net/manual/en/language.operators.arithmetic.php -- select 'mmarques' || '@' || 'unl.edu.ar' AS email; ---------------------------------------------------------
Martín Marqués          |   Programador, DBA
Centro de Telemática    |     Administrador
                Universidad Nacional
                     del Litoral
---------------------------------------------------------
-- ::Bruce:: -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#250039) next »