Re: [PHP] If value is odd or not

2006-06-07 Thread Dimiter Ivanov
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

Re: [PHP] If value is odd or not

2006-06-05 Thread Richard Lynch
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,

Re: [PHP] If value is odd or not

2006-06-05 Thread Adam Zey
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

[PHP] If value is odd or not

2006-06-02 Thread Jonas Rosling
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

Re: [PHP] If value is odd or not

2006-06-02 Thread Dave Goodchild
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

Re: [PHP] If value is odd or not

2006-06-02 Thread Brad Bonkoski
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

SV: [PHP] If value is odd or not

2006-06-02 Thread Jonas Rosling
-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

Re: [PHP] If value is odd or not

2006-06-02 Thread IG
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:

Re: [PHP] If value is odd or not

2006-06-02 Thread Jochem Maas
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 ;-):

Re: [PHP] If value is odd or not

2006-06-02 Thread Jochem Maas
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

RE: [PHP] If value is odd or not

2006-06-02 Thread Ford, Mike
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

Re: [PHP] If value is odd or not

2006-06-02 Thread IG
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

Re: [PHP] If value is odd or not

2006-06-02 Thread John Nichel
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

Re: [PHP] If value is odd or not

2006-06-02 Thread Jochem Maas
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.

RE: [PHP] If value is odd or not

2006-06-02 Thread Jay Blanchard
[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

Re: [PHP] If value is odd or not

2006-06-02 Thread tedd
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

Re: [PHP] If value is odd or not

2006-06-02 Thread Jochem Maas
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

Re: [PHP] If value is odd or not

2006-06-02 Thread Dimiter Ivanov
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

Re: [PHP] If value is odd or not

2006-06-02 Thread Steven Osborn
$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/)

Re: [PHP] If value is odd or not

2006-06-02 Thread John Meyer
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

Re: [PHP] If value is odd or not

2006-06-02 Thread tedd
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

RE: [PHP] If value is odd or not

2006-06-02 Thread Jay Blanchard
[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

RE: [PHP] If value is odd or not

2006-06-02 Thread tedd
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

RE: [PHP] If value is odd or not

2006-06-02 Thread tg-php
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

RE: [PHP] If value is odd or not

2006-06-02 Thread Jay Blanchard
[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

Re: [PHP] If value is odd or not

2006-06-02 Thread Adam Zey
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

RE: [PHP] If value is odd or not

2006-06-02 Thread tedd
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