php Tutorials
Creating An RSS Feed With PHP And MySQL
Retrieving XML With Curl and SimpleXML
Using curl to Query Remote Servers
MySQL Basics
PHP mySQL Voting Booth
File Download Security
PHP Fundamentals

PHP Fundamentals

Includes and functions

Includes and functions are great for storing routines that are used multiple times. Functions allow you to call routines that are used repeatedly with one line. Includes are excellent for loading variable sets or loading lists of functions that are used on multiple pages.

Includes

<? 
include ("config.php");
 ?>

Includes are self explanatory include ("{filename to include}");

Functions

<? 
function getmonth($month) {
    $montharray=array("01" => "January",
    "02"=>"February",
    "03"=>"March",
    "04"=>"April",
    "05"=>"May",
    "06"=>"June",
    "07"=>"July",
    "08"=>"August",
    "09"=>"September",
    "10"=>"October",
    "11"=>"November",
    "12"=>"December");
    $returnmonth=$montharray["$month"];
    return ($returnmonth);
}
 ?>

Variables in functions are exclusive to that function meaning setting a variable doesn't mean its set out of the function. Passing variables to a function is done with the function statement, put the variable in parentheses after the function name. Use the return statement to pass a variable back out of the function.

<? 
$month=getmonth("02");
 ?>

This runs the function getmonth and sets $month to February

Loops <<  1 2 3 4 5 6
New Content