Category: php

.

How to Write PHP functions Part 1

Author: D.Shaun Morgan

Versions and Skill Level
  • PHP 5
  • Reader skill level - Beginner
Tutorial Outline:
  1. Explanation Of PHP functions
  2. What is a PHP function
  3. How to Declare a php function
  4. Basic function syntax
  5. Example

Explanation of a Basic PHP Function

What is a PHP function?

In PHP a function is a piece of programming code that web developers use to perform a task -- usually a repetetive task. A PHP Function allows the user to re-use blocks of script without having to rewrite all the code everytime it's needed.

PHP comes with a lot functions already built into the PHP installation. So, before you decide to write a function, you should check the php manual. The function that you are looking for just might be there. After looking the PHP manual, you still are not able to find the PHP funciton that you need, then it's time to write your own function. A beginner php programmer, you will soon learn that functions are everywhere, and you really can't do a lot without them!

Declaring functions

Like other programming languages, PHP functions have to be declared. To declare PHP functions programmers either write the function at top of the document where the function will be used, or in a separate file. If the PHP function is declared in a separate file, the programmer has to make the function available to his/her script by using another php function such as include_once();.

PHP Function Syntax

All PHP functions start with the word "function," followed by a name for the function. It is suggested to use names that resemble what the PHP function does. Next, there will be "()", followed by "{". Now some code to do stuff, and finally another "}". Lets take a look at a declared php function.

Example PHP Function


<php

function my_first_fucntion(){

code to do something;

}

?>



Writing PHP Functions

Php function syntax is very similar to c and c++. Th main differences for pphp functions is that, just like php variables, they don't have to be delared or given a datatype. The PHP software figures out the function datatype for you.

Php functions, just like other programming languages, can take arguments and return something if you want them to. /p>

PHP Function Syntax | Example

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

how to write php functions php How to Write PHP functions Part 1 Author: D.Shaun MorganVersions and Skill Level PHP 5 Reader skill level - Begin

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

how to install php 5 php This is a quick start beginner's how-to manual explaining how to quickly setup a PHP 5 installation on a Windows XP PC. You must have an Apache webserver installed and working on your personal comp

.

 

Leave a Comment

how_to_write_php_functions.php

Name:      | Email:      | Website:

Comment:


captcha

Enter The Above Security Code: