Category: php


Explanation of a Basic PHP Function

What is a PHP function?

In PHP a function represents a block of instructions that perform a task. A PHP Function allows the user to re-use blocks of script without having to rewrite all the code every time it's needed. This is useful for repetitive tasks that perform the same jobs over and over.

PHP has a large number of built-in functions. Thus it is always good to check or Google before writing a function. There may already be one that you can use saving you a lot of time.

Declaring functions

Functions can be placed anywhere in a php document. However, it will make for easy-to-read code if you place your functions at the top of the document or in a separate file.

If you declared your PHP functions in a separate file, the functions must be made available to the main script using one of the include functions such as:

"include_once()". These functions are typically placed at the top of the main php document.

PHP Function Syntax

PHP functions start with the word "function," followed by a name for the function - a name that you give it.

ie. function myfunction(){} Use function names that resemble function's purpose.
Next you use: "()"

followed by:
Code goes between the curly brackets

<h3>PHP Function - Example</h3>
function my_first_function()
code to do something;
Author: D.Shaun Morgan

using php cookies variables Using Cookie Variables in PHP Setting cookies in php is pretty straight forward. There is a php function: setcookie(); This function mu

stop form spam captcha php PHP -- How to Protect My Email Form / Contact Form Against Spam Bots Author: D.Shaun Morgan Versions and Skill Level PHP 5

retreive images mysql php php How to get images out of mysql database with php and use them on my webpages Author: D.Shaun Morgan PHP Version - PHP 5x

store images mysql php php Storing Images in Mysql Database Tutorial Outline: Creating a Test Mysql Database Example php Database Functio

register globals long arrays php Security, php.ini, register_globals and register_long_arrays Author: D.Shaun Morgan Versions and Skill Level PHP Version - PHP 5x


Leave a Comment


Name:      | Email:      | Website:



Enter The Above Security Code: