Re: Passing an array as an argument.
| From: | Christian Reiniger | Date: | Wed, 07 Feb 2001 10:45:22 +0000 |
| Subject: | Re: Passing an array as an argument. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-38518@lists.php.net to get a copy of this message | ||
On Tuesday 06 February 2001 18:18, April wrote:
> How do you pass an array as an argument to a function?
Just as any other variable. Read on...
> function process_members($asker_rank, $email) {
>
> global $database_mysql;
> mysql_select_db($database_mysql);
>
> 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);
Look at the definition of process_members() again. The function takes two
values. The first is called $asker_rank and the second $email.
Now you pass *three* values to it. #1, $asker_rank, is fine. But #2,
$total_members, is passed in place of $email, so every time the function
body accedded its "$email" parameter, it gets the value of $total_members
- which is not an array.
The third parameter is ignored.
--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)
"Software is like sex: the best is for free" -- Linus Torvalds