Ben Luey writes:
> Php question guys.
> 
> I want to write a function so I can run in php:
> 
> $result = mysql_query($query);
> 	while ($line = mysql_fetch_assoc($result)){
> 	user_call_func_array('displayresults', $line);
> 	}
> 
> where displayresults takes the results from the query and formats them.
> The problem is that the fields returned in the array change depending
> onthe query (I have multiple tables with different fields). So I can't
> really reduce the array $line into a set of variables. But when I try to
> pass the array $line, the function displayresults only gets $line as a
> string. Same with user_call_func.
> 
> Can I pass an array to a function?

Yes, you can. You just have to make sure to prototype the variable in
your function. Like this:

-------------------------
 $my_array = array (
  		   "foo" => "bar",
 		   "knuckle" => "head",
 		   );

 my_func ('displayresults', $my_array);


 function my_func ($string, $your_array) {
    echo "String: $string <br>";
    echo "Array: " . $your_array['knuckle']";

    return;
 }
-------------------------


Regards,

    Matt

-- 
For technical support contracts, visit https://order.mysql.com/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Mr. Matt Wagner <mwagner at mysql.com>
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Herr Direktor
/_/  /_/\_, /___/\___\_\___/   Hopkins, Minnesota  USA
       <___/   www.mysql.com