Introduction to PHP – 4

More about Functions

function with arguments.

<?php

define(“name” , “Gajjar”);
echo name;

function karan($k){
echo “<br>hi $k”;

}

karan(“k1”);
karan(“k2”);
karan(“k3”);
karan(name);
?>

NOTE: define(“name”,”Gajjar”) is same as a #define in C.

by default it is not case sensitive. Means in the second line if you echo NaME you will get error. To do so you need to define like this define(“name”,”Gajjar”,true); now you can echo as NAME ect.

One more imp : thing this define is called constant and these are global you can use it in function too!


function with Return type.

<?php

function multi($x,$y){

$z = $x*$y;
return $z;

}

echo “5 * 2 =”.multi(5,2).”<br>”;
echo “10 * 5 =”.multi(10,5).”<br>”;
echo “15 * 10 =”.multi(15,10).”<br>”;
?>


function with Two arguments.

<?php

function name($first,$age=20){

echo “<br>$first is $age”;

}

name(“Karan”,19);
name(“Vatsal”,26);
name(“Milan”);

?>

These are so simple just remember syntax.Though if you have doubt feel free to ask!

Other inbuilt function in PHP you can find on internet.Btw we will try to cover in examples.!

Advertisements

Author: kanu_lp

Teck Geek guy... Bands Obsessed.

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