Posted by: Sourav | February 22, 2011

More Functions in PHP


<html>
<head>
<title>
Functions
</title>
</head>
<body>
<?php

function sourav()
{
echo “Hello World!<br />”;
}

sourav();
function sourav1($word)
{
echo “Hello {$word}!<br />”;
}

sourav1(“everyone”);
sourav1(“ladies”);
sourav1(“baby”);
$name=”Sourav Bhattacharya”;
sourav1($name);
function sourav3($greeting,$target,$punct)
{
echo $greeting.”, “.$target.” “.$punct.”<br />”;
return true;
}
sourav3(“hello”,$name,”!”)
?>
<?php

function add($val1,$val2)
{
$sum=$val1+$val2;
return $sum.”<br />”;
}
$summation=add(3,4);
echo $summation;

add(10,5);//no result because the return value is not catched by anyone

if(add(10,5)==15)//this produces yes which is quiet surprising to me
{
echo “yes.<br />”;
}

function addandsubtract($value1,$value2)
{
$sum=$value1+$value2;
$subtract=$value1-$value2;
$result=array($sum,$subtract);
return $result;
}

$resultarray=addandsubtract(15,10);
echo “Sum= $resultarray[0]<br />”;
echo “Subtract=$resultarray[1]<br />”;

?>
</body>
</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: