1. Home
  2. Computing & Technology
  3. PHP / MySQL

Learn PHP - All About PHP Functions

By , About.com Guide

5 of 5

More Function Writing

Functions can contain any of the information we have learned so far. Let's combine functions with some of the material we learned earlier to create a multiplication table:

<?php
function mul()
{
global $start;
print "<tr>";
for ($num=1; $num <= 10; $num++ )
{
$cell = $num * $start;
print "<td> " . $cell . " </td>";
}
print "</tr>";
}
$start = 0;
print "<table border=1 cellpadding=3>";
while ( $start <=10 )
{
mul();
$start++;
}
print "</table>";
?>

One new thing you may have noticed is "GLOBAL". Since the variable $start is not defined within the function, we use the tag "GLOBAL" to let it know that it needs to use the $start variable that we have defined outside of the function.

Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Learn PHP
  5. Learn PHP Functions - Write PHP Functions - PHP Functions Tutorial

©2009 About.com, a part of The New York Times Company.

All rights reserved.