Page 1 of 1

[SOLVED] Change odd number to first highest even number?

Posted: Thu Sep 09, 2004 6:50 am
by tomfra
I don't know if there is a simple solution but just in case...

I want to get the first highest *even* number for a given odd number.

I.e.: if $odd = 15 I want to get $even = 16 .

Any idea?

Thanks!

Tomas

Posted: Thu Sep 09, 2004 6:58 am
by CoderGoblin

Code: Select all

if (fmod($odd,2)) $even=$odd+1;
For a better understanding I would recommend you look at fmod, floor and ceil...
http://www.php.net/manual/en/ref.math.php

Posted: Thu Sep 09, 2004 7:04 am
by tomfra
Suberb, thanks!

Tomas