On 6/5/06, Adam Zey <[EMAIL PROTECTED]> wrote:
Let's make it even more compact and confusing :)
echo "$variable is ".($variable % 2 ?'even':'odd')."\n";
I'm not sure if you can nuke the whitespace in the modulus area or not.
Yes you can,in php whitespaces inside expressions does not have
sp
Richard Lynch wrote:
On Fri, June 2, 2006 8:32 am, Jonas Rosling wrote:
is there any easy why to check if a value is odd or not?
$parity = $variable % 2 ? 'even' : 'odd';
echo "$variable is $parity\n";
Let's make it even more compact and confusing :)
echo "$variable is ".($variable % 2 ?'e
On Fri, June 2, 2006 8:32 am, Jonas Rosling wrote:
> is there any easy why to check if a value is odd or not?
$parity = $variable % 2 ? 'even' : 'odd';
echo "$variable is $parity\n";
--
Like Music?
http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, v
At 10:10 AM -0500 6/2/06, Jay Blanchard wrote:
>[snip]
>It's interesting to dangle bait above a pool of programmers and see what
>rises. :-)
>
>There used to be a contest to create the most complicated solution to
>accomplish a very trivial task, like turning on a light switch. However,
>I can't re
IG wrote:
Jochem Maas wrote:
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
ignore every answer that doesn't use the % operator.
Thanks // Jonas
ie my answer! I think the % operator is the best way, but there was
nothing wrong with the answer I g
[snip]
It's interesting to dangle bait above a pool of programmers and see what
rises. :-)
There used to be a contest to create the most complicated solution to
accomplish a very trivial task, like turning on a light switch. However,
I can't remember what the contest was called -- it was something
The Obfuscated C contest had a category for most complicated solution to a
simple problem. Like 50 lines of code to add two numbers together, stuff like
that.
-TG
= = = Original message = = =
At 9:52 AM -0500 6/2/06, Jay Blanchard wrote:
>[snip]
>It might be interesting to see how long of a p
At 9:52 AM -0500 6/2/06, Jay Blanchard wrote:
>[snip]
>It might be interesting to see how long of a piece of code could be
>written to answer the same question.
>[/snip]
>
>I can think of a really long one using a callback function
It's interesting to dangle bait above a pool of programmers and s
[snip]
It might be interesting to see how long of a piece of code could be
written to answer the same question.
[/snip]
I can think of a really long one using a callback function
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
At 5:14 PM +0300 6/2/06, Dimiter Ivanov wrote:
>I doubt that Jonas ever expected 'the rain of answers' that will
>follow his humble question ;]
Well... at least the answers are getting shorter.
It might be interesting to see how long of a piece of code could be written to
answer the same questio
Steven Osborn wrote:
$odd = array("1","3","5","7","9");
if(inarray(substr($var,strlen($var)-1,1),$od)
{
//haha
}
else
{
//even
}
How about this
if ($var % 2 == 0) { //it's even
} else { //it's odd
}
--
Online library -- http://pueblonative.110mb.com
126 books and counting.
--
PHP Gener
$odd = array("1","3","5","7","9");
if(inarray(substr($var,strlen($var)-1,1),$od)
{
//haha
}
else
{
//even
}
p.s. sorry for the direct mail
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
Thanks // Jonas
--
PHP General Mailing List (http://www.ph
I doubt that Jonas ever expected 'the rain of answers' that will
follow his humble question ;]
On 6/2/06, tedd <[EMAIL PROTECTED]> wrote:
At 3:32 PM +0200 6/2/06, Jonas Rosling wrote:
>Hi all,
>is there any easy why to check if a value is odd or not?
Jonas:
echo($num & 1);
This produces 1 for
John Nichel wrote:
Jochem Maas wrote:
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
ignore every answer that doesn't use the % operator.
if ( is_int ( $value / 2 ) ) {
// Even
}
LOL.
:-p
--
PHP General Mailing List (http://www.php.net
At 3:32 PM +0200 6/2/06, Jonas Rosling wrote:
>Hi all,
>is there any easy why to check if a value is odd or not?
Jonas:
echo($num & 1);
This produces 1 for odd and 0 for even.
tedd
--
http://sperling.com htt
[snip]
if ( is_int ( $value / 2 ) ) {
// Even
}
[/snip]
:)
More?
$oddArray = array(1,3,5,7,9);
if(in_array(substr($integer, -1, 1))){
echo $integer . " is odd\n";
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
IG wrote:
Jochem Maas wrote:
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
ignore every answer that doesn't use the % operator.
Thanks // Jonas
ie my answer! I think the % operator is the best way, but there was
not just your answer.
nothi
Jochem Maas wrote:
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
ignore every answer that doesn't use the % operator.
if ( is_int ( $value / 2 ) ) {
// Even
}
:-p
--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of B
Jochem Maas wrote:
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
ignore every answer that doesn't use the % operator.
Thanks // Jonas
ie my answer! I think the % operator is the best way, but there was
nothing wrong with the answer I gave in that
On 02 June 2006 14:32, Jonas Rosling wrote:
> Hi all,
> is there any easy why to check if a value is odd or not?
if ($value%2):
// $value is odd
endif;
Cheers!
Mike
-
Mike Ford, Electronic Information Services Adv
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
ignore every answer that doesn't use the % operator.
Thanks // Jonas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
the modulos operator:
read about what it does here:
http://php.net/manual/en/language.operators.arithmetic.php
here is a simple example of how to check if something
is odd or not (odd number that is ;-):
$x
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
Thanks // Jonas
$value = 3;
if (strpos(($value/2),".") === FALSE) {echo "even";}
else {echo "odd";}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www
if ($value % 2 == 0 )
echo "Value is even";
else
echo "Value is odd";
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?
Thanks // Jonas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
On 02/06/06, Jonas Rosling <[EMAIL PROTECTED]> wrote:
Hi all,
is there any easy why to check if a value is odd or not?
Thanks // Jonas
Yep, use the modulo operator like so:
if ($value % 2 ==0) $odd = false;
--
http://www.web-buddha.co.uk
dynamic web programming from Reigate, Surre
25 matches
Mail list logo