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').br /\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
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 $paritybr /\n;
--
Like Music?
http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe,
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 $paritybr /\n;
Let's make it even more compact and confusing :)
echo $variable is .($variable % 2
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, Surrey
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
-Ursprungligt meddelande-
Fran: Eric Mol [mailto:[EMAIL PROTECTED]
Skickat: den 2 juni 2006 15:34
Till: 'Jonas Rosling'; 'PHP List'
Amne: RE: [PHP] If value is odd or not
If ($var/2==round($var/2)){
// not odd
}else{
// odd
}
Greetings,
Eric
Thanks (all)!
-Oorspronkelijk
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:
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 ;-):
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
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
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
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
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.
[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
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
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
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 odd
$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.php.net/)
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 General
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
[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 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 see
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
[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
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
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 remember
27 matches
Mail list logo