Home >>PHP Object Oriented >Php Check Number in Function

Php Check Number in Function


PHP Check Numbers parametrized Function

<?php 
//my add function structure
function add($x,$y)
{
	if(is_numeric($x) && is_numeric($y))
	{
	$res=$x+$y;
	echo "<h3 style='color:blue'>Sum of two numbers=".$res."</h3>";
	}
	else
	{
	echo "<h3 style='color:red'>Both Number must be numeric </h3>";
	}

}

//call my add function
extract($_POST);
if(isset($add))
{
	//Now call my add function
	add($fn,$sn);
}
?>
<html>
	<head>
		<title>Parametrized Function</title>
	</head>
	<body>
		<form method="post">
			<table border="1">
				<tr>
					<td>Enter Your first number</td>
					<td><input type="text" name="fn"/></td>
				</tr>
				<tr>
					<td>Enter Your first number</td>
					<td><input type="text" name="sn"/></td>
				</tr>
				<tr>
					<td colspan="2" align="center">
					<input type="submit" name="add" value="+"/></td>
				</tr>
			</table>
		</form>
	</body>
</html>

Popular Tutorials