note 36601 deleted from function.explode by kennyt
| From: | kennyt@php.net | Date: | Sat, 28 Feb 2004 20:26:16 +0000 |
| Subject: | note 36601 deleted from function.explode by kennyt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65951@lists.php.net to get a copy of this message | ||
Note Submitter: woodspire@hotmail.com
----
This is an addendum to joelith at cyberone dot com dot au's note.
First of all, here is the correct code for your example:
...
$temp = explode('.', $test);
...
There was a variable name error.
Also, you may have never heard of the modulus operator, but it's quite simpler with it.
Ex:
$test = 5 % 2; // $test = 1;
$test = 4 % 2; // $test = 0;
So, the easiest way to find if a number is even or odd is the following:
$test = $number % 2;
if ($temp == 0){
// even
}
else{
//odd
}