RE: [PHP] Two little questions

2001-01-14 Thread mOrP

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.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Two little questions

2001-01-14 Thread mOrP


 function check_alias_password()
 global $alias, $password;

better:

global $alias;
global $password;

 {
 if ((!$alias) || (!$password)) {
 header("Location: login.php");
 exit;
 }
 }

 check_alias_password();

 work? Or would the last example need to be globals (variables) instead of
 global?


Yes, this will work - with the correction I've made, 'cause I'm not sure, if
you can assign two variables to 'global'...

But you can see, that it is not good to use the 'global' keyword, because
you must know the name of the variable, you use.

Look:


$name_1 = "Jan";
$name_2 = "Fritz";

function print_name($name_arg)
{
echo $name_arg;
}

print_name($name_1);
print_name($name_2);


You see, how flexible it is...

CU
mOrP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]