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

Learn PHP - All About PHP Functions

By Angela Bradley, About.com

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.

Index: Learn PHP - All About PHP Functions

  1. PHP Functions
  2. Time and Date
  3. Date Function Formatting
  4. Writing Functions
  5. More Function Writing

5 of 5

Explore PHP / MySQL

More from About.com

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

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

All rights reserved.