RE: [PHP] Two little questions
| From: | mOrP | Date: | Sun, 14 Jan 2001 16:57:22 +0000 |
| Subject: | RE: [PHP] Two little questions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-34478@lists.php.net to get a copy of this message | ||
James,
> function CUP (
> if ((!$alias) || (!$password)) {
> header("Location: login.php");
> exit;
> }
> );
>
usually a function has the following structure:
function <name> ( <arguments> ) { <code> }
of course you can put any whitspace inside:
function <name> ( <arguments> )
{
<code>
}
which makes it easy to read.
You can put anything you want inside a function, but you must know, that you
cannot directly access a variable, that is defined outside the function.
$name = "mOrP";
function print_name()
{
echo $name;
}
print_name();
will not work.
Then you must 'get' the global variables (like $name):
$name = "mOrP";
function print_name()
{
global $name;
echo $name;
}
print_name();
But it's better to work with the function arguments:
$name = "mOrP"
function print_name($name_arg)
{
echo $name_arg;
}
print_name($name);
notice, that there is no ";" behind the { ... } and the ( ... ) block in the
definition of the function.
Hope it helps,
mOrP.