AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

PHP Function


<< Previous Page
Convert Array to String
Next Page >>
PHP GET and POST



The php function is similar to other functions from other programming languages.
The function is a pice of programming code which takes one or more inputs as parameters and does some processing and returns a value.

A user-defined function declaration starts with the word function:
Syntax:
function functionName() {
code to be executed;
}

Creating PHP Function - how? - example


In the example below, we have created a function named "WriteMyMessage()".
The function outputs "This is your first PHP function. Have a nice day".
To call the function, just write its name:

Example 1: Using implode() to go from an Array to a String
<?php
/* Defining a PHP Function */
function WriteMyMessage() {
echo "This is your first PHP function.
Have a nice day"
;
}
/* Calling a PHP Function */
WriteMyMessage();
?>

PHP cod above will display this result -

css border radius

Note: There are two parts of function which should be clear to you −
Creating a PHP Function
Calling a PHP Function

PHP Functions with Parameters - How to create

PHP gives you the option to pass parameters into a function. You can pass as many parameters as you can.
The following example has three integer parameters, adds them and then prints them together.

Example 2:
<?php
function addFunction ( $number1, $number2, $number3 ) {
$sum = $number1 + $number2 + $number3;
echo "Sum of the three numbers is : $sum" ;
}
addFunction( 10, 20, 40);
?>

The PHP cod above will display this result -

<< Previous Page
Convert Array to String
Next Page >>
PHP GET and POST




php function, exist, return, return array, get _exists, as argument
PHP Function, Creating PHP Function - how? - example - php tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.