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

PHP Functions: by S.Abinaya 13N103

This document discusses PHP functions including: 1. PHP allows users to create their own functions that can be reused throughout a program. A function declaration starts with the "function" keyword and contains code to be executed. 2. Functions can accept arguments to allow passing of information. Arguments are specified inside the parentheses after the function name and are separated by commas. 3. Functions can return values using the "return" statement. This allows calling the function and using the returned value in expressions or output.

Uploaded by

haritha
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

PHP Functions: by S.Abinaya 13N103

This document discusses PHP functions including: 1. PHP allows users to create their own functions that can be reused throughout a program. A function declaration starts with the "function" keyword and contains code to be executed. 2. Functions can accept arguments to allow passing of information. Arguments are specified inside the parentheses after the function name and are separated by commas. 3. Functions can return values using the "return" statement. This allows calling the function and using the returned value in expressions or output.

Uploaded by

haritha
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PHP FUNCTIONS

By
S.Abinaya
13N103

Besides

the built-in PHP functions, we can create our


own functions
A function is a block of statements that can be used
repeatedly in a program
A function will not execute immediately when a page
loads
A function will be executed by a call to the function

PHP USER DEFINED FUNCTIONS

A user

defined function declaration starts with the


word "function":

SYNTAX

function functionName() {
codetobeexecuted;
}

CREATE A USER DEFINED


FUNCTION IN PHP

<?php
function writeMsg() {
echo "Hello world!";
}
writeMsg(); // call the function
?>

EXAMPLE

Information

can be passed to functions through


arguments. An argument is just like a variable.
Arguments are specified after the function name,
inside the parentheses. You can add as many
arguments as you want, just separate them with a
comma.

PHP FUNCTION ARGUMENTS

<?php
function familyName($fname) {
echo "$fname Refsnes.<br>";
}
familyName("Jani");
familyName(Krishna");
?>

EXAMPLE

<?php
function familyName($fname, $year) {
echo "$fname Refsnes. Born in $year <br>";
}
familyName(Udhaya", "1991");
familyName(Jani", "1996");
?>

EXAMPLE With two arguements

<?php
function setHeight($minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
?>

PHP DEFAULT ARGUMENT VALUE

<?php
function sum($x, $y) {
$z = $x + $y;
return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>

PHP FUNCTIONS - RETURNING


VALUES

THANK YOU

You might also like