try:
function process_members($asker_rank, $total_members, $email=array()) {
global $database_mysql;
mysql_select_db($database_mysql);
while (list ($key, $val) = each ($email)) {
echo "$key => $val<br>";
}
}
process_members($asker_rank, $total_members, $email);
Your original function declaration only has two variables passed to it. You
are passing three variables when you call the function.
What's happening is this:
function process_members($asker_rank, $email) {
global $database_mysql;
mysql_select_db($database_mysql);
while (list ($key, $val) = each ($email)) {
echo "$key => $val<br>";
}
}
process_members($asker_rank, $total_members, $email);
step one:
php sets $asker_rank (in function declaration) equal to $asker_rank
step two:
php sets $email (in function declaration) equal to $total_members
step three:
php ignores $email array passed to process_members()
step four:
php passes $email to each(). $email is set to the value
of $total_members, which is not an array, and chokes.
Using :
function process_members($asker_rank, $total_members, $email=array())
{
...
}
allows you to have a default value for $email. So you can either pass it or
not.
-----Original Message-----
From: April [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 06, 2001 12:18 PM
To: PHP General
Subject: [PHP] Passing an array as an argument.
How do you pass an array as an argument to a function?
My code (or at least the important parts):
function process_members($asker_rank, $email) {
global $database_mysql;
mysql_select_db($database_mysql);
while (list ($key, $val) = each ($email)) {
echo "$key => $val<br>";
}
}
######### This will display fine. #########
while (list ($key, $val) = each ($email)) {
echo "$key => $val<br>";
}
######### Doing the same thing with the function here returns this error,
though. ########
// Warning: Variable passed to each() is not an array or object in lib.inc
on line 447
process_members($asker_rank, $total_members, $email);
--
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]
--
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]