0% found this document useful (0 votes)
11 views

Function in PHP

Uploaded by

SANJEET KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Function in PHP

Uploaded by

SANJEET KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Function in PHP:

Function is a part of program that are used to perform some specific task.

program:

<?php

function test()

echo "HELLO-PHP";

test();

?>

function with argument:

<?php

function test($name)

echo "HELLO $name";

test("khushbu");

?>
Program to calculate square of a number:

<?php

function square($num)

return $num*$num;

echo square(5);

?>

Program to calculate cube of a number:

<?php

function cube($num)

return $num*$num*$num;
}

echo cube(5);

?>

Pass two arguments with function:

<?php

function student($name, $roll)

echo "Student name: $name <BR>";

echo "Roll number: $roll <BR> ";

student("ABC","1");

student("XYZ","2");

?>
Call by reference

<?php
//call by reference
function add(&$x)
{
$x= $x+1;
}
$num=5;
add($num);
echo "number= $num <br>";
?>

You might also like