Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Sedo - Buy and Sell Domain Names and Websites project info: programmershelp.co.uk Statistics for project programmershelp.co.uk etracker® web controlling instead of log file analysis

   Misc

   Amazon

   Links

    


Odd or Even number

 

This is a very popular type of function on other programming sites and here is our php version of this . All this does is simply display a message whether a value is odd or even .

Here is the script in full

<?php
/*
This function takes a whole number ($intnumber)
and then displays a message depending on whether
it is odd or even
*/
function OddOrEven($intNumber)
{
if ($intNumber % 2 == 0 )
{
//your number is even
echo "Your number is even<br>";
}
else
{
//your number is odd
echo "Your number is odd<br>";
}
}
//test the function with 2 values 40 and 3
OddOrEven(40);
OddOrEven(3);
?>

A note here for people coming from other languages , in particular Visual Basic or VBscript . The modulus operator is % and not MOD . If you program in more than one language this will catch you out from time to time.

 

 

 

 

 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
mouse position(VB)
Ceil function(C)
File System of drive(ASP)
convert an IP address to a hostname(C Sharp)
displays some disk drive parameter in an excel spreadsheet(VBScript)
image as a list item marker(CSS)
Move a folder with MoveTo(C Sharp)
display info using wmi(VB)

    




Copyright © 2003 by programmershelp.co.uk