[UPHPU] Coding Correctness
Justin Giboney
jgiboney at gmail.com
Wed Oct 8 17:18:18 MDT 2008
The reason I used is_int, is because 1.4 is divisible by 2 but according
to wiki, it isn't an even number.
Justin Giboney
> What about error handling the case where a sting is passed to the function?
> This function handles the '3', and the 'your name'
>
> function evenOrOdd ($number) {
> if (is_numeric($number)) {
> $evenOrOdd = 'odd';
> if (($number % 2) == 0)
> {
> $evenOrOdd = 'even';
> }
> print $evenOrOdd."\n";
> }
> else {
> throw new Exception('Argument is invalid, it must be a number');
> }
> }
>
>
> - Kirk
>
More information about the UPHPU
mailing list