Function in PHP
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();
?>
<?php
function test($name)
test("khushbu");
?>
Program to calculate square of a number:
<?php
function square($num)
return $num*$num;
echo square(5);
?>
<?php
function cube($num)
return $num*$num*$num;
}
echo cube(5);
?>
<?php
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>";
?>