> That won't work. % returns the remainder from a division of
> the number divided by the mod number.
Yours:
> if($num %2 == 0){
> echo "even";
> }else{
> echo "odd";
> }
Mine:
> > if( $num % 2 ) {
> > echo "Odd";
> >
> > } else {
> > echo "Even";
> >
> > }
Ours are identical, just the other way around. This:
if( $num % 2 ) {
means if the result of that operation is anything other than
0 (zero), which is a truth in PHP.
Chris
- [PHP] Is it odd or even??? Brandon Orther
- Re: [PHP] Is it odd or even??? Jon Rosenberg
- RE: [PHP] Is it odd or even??? Brian V Bonini
- RE: [PHP] Is it odd or even??? Optimize!!! Nathan Cassano
- Re: [PHP] Is it odd or even??? Optimize!!! Julian Wood
- RE: [PHP] Is it odd or even??? Boget, Chris
- RE: [PHP] Is it odd or even??? Larry Jeannette
- RE: [PHP] Is it odd or even??? Boget, Chris
- RE: [PHP] Is it odd or even??? John Guynn
- RE: [PHP] Is it odd or even??? Boget, Chris

