I wanted to create something today, so I made this. The idea is very basic, you have two functions (Odd and Even). Using Odd: this allows you to find out if an integer is an odd number (cannot be divided by two). Using Even: this allows you to find out if an integer is an even number (Can be divided by two). Both functions return false or true depending on the out-come.
PHP FUNCTION(S):
number: even ( string: $int )
number: odd ( string $int )
Parameters:
$int: (Required)
- Classification: String
- Allows: Integers
- is Array: no
Examples:
<?php
require("path/to/your/odd_even.php");
// True statements //
if(even("12") == true){
echo "using even, we figured out that 12 is an even number!";
}
if(odd("11") == true){
echo "using odd, we figured out that 11 is an odd number!";
}
//False statements//
if(even("9") == false){
echo "using even, we have figured out that 9 is odd number";
}
if(odd("22") == true){
echo "using odd, we figured out that 22 is an even number.
}
?>
This is really meant for strings that you have not a clue what the integer will be. I will give an example, lets say I had a database table with an “id” field. I gave the id an auto_increment value. Now, I am going to display the content, but I want a background color for each different field. This is where odd and even functions come into play.
Example of above:
<?php
require("path/to/your/odd_even.php");
//Mysql Database Connection//
mysql_connect("localhost","****","*****");
mysql_select_db("******") or die( "Error: database connect failed.");
//query string//
$query = mysql_query("SELECT * FROM `content`");
//while (loop)//
while($row = mysql_fetch_array($query)){
echo "<div style="background-color:";
if(even($row['id'])){
// prints red background color//
echo "#f00";
}else{
// prints white background color//
echo "#FFF";
}
}
?>
Download Function File
By downloading you agree to:
all rights remain to Grant Gould. I will not sell this file for any reason. I will not remove the credits to it’s creator. I will not use this in illegal ways. USE AS IS, THERE IS NO WARRANTY.
If you have any problems or find error’s drop a comment below. Hope this was helpful for you!


