Specifications

Many languages do allow you to reuse function names. This feature is called function over-
loading. However, PHP does not support function overloading, so your function cannot have
the same name as any built-in function or an existing user-defined function. Note that although
every PHP script knows about all the built-in functions, user-defined functions only exist in
scripts where they are declared. This means that you could reuse a function name in a different
file, but this would lead to confusion and should be avoided.
The following function names are legal:
name()
name2()
name_three()
_namefour()
These are illegal:
5name()
name-six()
fopen()
(The last would be legal if it didnt already exist.)
Parameters
In order to do their work, most functions require one or more parameters. A parameter allows
you to pass data into a function. Here is an example of a function that requires a parameter.
This function takes a one-dimensional array and displays it as a table.
function create_table($data)
{
echo “<table border = 1>”;
reset($data); // Remember this is used to point to the beginning
$value = current($data);
while ($value)
{
echo “<tr><td>$value</td></tr>\n”;
$value = next($data);
}
echo “</table>”;
}
If we call our create_table() function as follows:
$my_array = array(“Line one.”,”Line two.”,”Line three.”);
create_table($my_array);
we will see output as shown in Figure 5.4.
Using PHP
P
ART I
134
07 7842 CH05 3/6/01 3:35 PM Page 134