Blog Details

PHP Function


                                
                                    <h2>* PHP Function :-</h2>
<ul>
	<li>A function is a <strong>block of statements</strong> that can be used<strong> repeatedly</strong> in a program.</li>
	<li>A function <strong>will not</strong> execute immediately when a <strong>page loads</strong>.</li>
	<li>A function will be <strong>executed</strong> by a <strong>call to the function</strong>.</li>
</ul>
&nbsp;
<h3><strong>Syntax :-</strong></h3>
&nbsp;

<strong>function <i>functionName</i>()</strong>
{
<i>code to be executed</i>;
}
<h3>Example :-</h3>
&nbsp;

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

writeMsg(); // call the function
?&gt;
<h2>* PHP Function Arguments :-</h2>
<ul>
	<li>Information can be<strong> passed</strong> to functions through <strong>arguments</strong>. An argument is just like a variable.</li>
	<li>Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just seperate them with a comma.</li>
</ul>
&nbsp;
<h3>Example :-</h3>
&nbsp;

&lt;?php
function familyName($fname)
{
echo "$fname Refsnes.&lt;br&gt;";
}

familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");
?&gt;
<h3><strong> Output Result :-</strong></h3>
&nbsp;

Jani Refsnes.
Hege Refsnes.
Stale Refsnes.
Kai Jim Refsnes.
Borge Refsnes.

&nbsp;
                                    


Categories

Core_PHP

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote