<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Is number odd or even?</title>
	<link>http://www.php-scripts.com/20051104/57/</link>
	<description>Writing about PHP scripting since 12/99. Learn something new every day.</description>
	<pubDate>Fri, 10 Sep 2010 05:11:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>

	<item>
		<title>By: JKLZ</title>
		<link>http://www.php-scripts.com/20051104/57/#comment-93896</link>
		<dc:creator>JKLZ</dc:creator>
		<pubDate>Sat, 04 Oct 2008 07:39:47 +0000</pubDate>
		<guid>http://www.php-scripts.com/20051104/57/#comment-93896</guid>
		<description>there is a problem with your code. it won't work you forgot a ")" it should have 3 of them after the H becuase you got to finish the date then the function then the if so it should look like this instead.


function is_odd($number) {
  return $number &#38; 1; // 0 = even, 1 = odd
}

if(is_odd(date(“H”))) {
        print “Since it’s an odd hour, I’ve got an odd message for you: read and be happy”;
} else {
        print “It’s an even hour, Steven.”;
}</description>
		<content:encoded><![CDATA[<p>there is a problem with your code. it won&#8217;t work you forgot a &#8220;)&#8221; it should have 3 of them after the H becuase you got to finish the date then the function then the if so it should look like this instead.</p>
<p>function is_odd($number) {<br />
  return $number &amp; 1; // 0 = even, 1 = odd<br />
}</p>
<p>if(is_odd(date(“H”))) {<br />
        print “Since it’s an odd hour, I’ve got an odd message for you: read and be happy”;<br />
} else {<br />
        print “It’s an even hour, Steven.”;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad Koch</title>
		<link>http://www.php-scripts.com/20051104/57/#comment-88113</link>
		<dc:creator>Brad Koch</dc:creator>
		<pubDate>Wed, 23 Jul 2008 14:20:00 +0000</pubDate>
		<guid>http://www.php-scripts.com/20051104/57/#comment-88113</guid>
		<description>You might want to consider changing this:
   return $number &#38; 1; // 0 = even, 1 = odd
to this:
   return ($number &#38; 1) ? true : false; // false = even, true = odd

Just for the sake of returning a pure boolean.  Although it really shouldn't matter in most cases.</description>
		<content:encoded><![CDATA[<p>You might want to consider changing this:<br />
   return $number &amp; 1; // 0 = even, 1 = odd<br />
to this:<br />
   return ($number &amp; 1) ? true : false; // false = even, true = odd</p>
<p>Just for the sake of returning a pure boolean.  Although it really shouldn&#8217;t matter in most cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.php-scripts.com/20051104/57/#comment-75971</link>
		<dc:creator>David</dc:creator>
		<pubDate>Thu, 08 May 2008 18:03:17 +0000</pubDate>
		<guid>http://www.php-scripts.com/20051104/57/#comment-75971</guid>
		<description>You missed an ) on the last example</description>
		<content:encoded><![CDATA[<p>You missed an ) on the last example</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cristian</title>
		<link>http://www.php-scripts.com/20051104/57/#comment-57197</link>
		<dc:creator>Cristian</dc:creator>
		<pubDate>Thu, 20 Dec 2007 23:20:42 +0000</pubDate>
		<guid>http://www.php-scripts.com/20051104/57/#comment-57197</guid>
		<description>Thanks, this is really useful. Been using it for some time. is_odd() helps with creating alternate table row classes too, for SQL results and such.</description>
		<content:encoded><![CDATA[<p>Thanks, this is really useful. Been using it for some time. is_odd() helps with creating alternate table row classes too, for SQL results and such.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vinay kapadia</title>
		<link>http://www.php-scripts.com/20051104/57/#comment-55881</link>
		<dc:creator>vinay kapadia</dc:creator>
		<pubDate>Fri, 14 Dec 2007 19:54:39 +0000</pubDate>
		<guid>http://www.php-scripts.com/20051104/57/#comment-55881</guid>
		<description>I tried this, but I couldnt get it to work. I used:

if($number &#38; 1)

and

if($number &#38; 0)

and it would be all screwy, sometimes work sometimes not. The code I got to work is:

if($number % 2)

to check for odd numbers, and

if(!($number % 2))

for even numbers. I like this better cause, well, I could get it to work, and also cause it's intuitive. Divisable by 2? then even. Not divisible by 2? then odd.</description>
		<content:encoded><![CDATA[<p>I tried this, but I couldnt get it to work. I used:</p>
<p>if($number &amp; 1)</p>
<p>and</p>
<p>if($number &amp; 0)</p>
<p>and it would be all screwy, sometimes work sometimes not. The code I got to work is:</p>
<p>if($number % 2)</p>
<p>to check for odd numbers, and</p>
<p>if(!($number % 2))</p>
<p>for even numbers. I like this better cause, well, I could get it to work, and also cause it&#8217;s intuitive. Divisable by 2? then even. Not divisible by 2? then odd.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://www.php-scripts.com/20051104/57/#comment-52820</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Wed, 28 Nov 2007 15:38:52 +0000</pubDate>
		<guid>http://www.php-scripts.com/20051104/57/#comment-52820</guid>
		<description>Thanks for this, a great quick answer - just what I needed</description>
		<content:encoded><![CDATA[<p>Thanks for this, a great quick answer - just what I needed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derek</title>
		<link>http://www.php-scripts.com/20051104/57/#comment-9490</link>
		<dc:creator>derek</dc:creator>
		<pubDate>Tue, 09 Jan 2007 18:44:53 +0000</pubDate>
		<guid>http://www.php-scripts.com/20051104/57/#comment-9490</guid>
		<description>Very nice and quick lesson.  Just what I was looking for</description>
		<content:encoded><![CDATA[<p>Very nice and quick lesson.  Just what I was looking for</p>
]]></content:encoded>
	</item>
</channel>
</rss>
