Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2000071

[PHP] Re: [PHP-GENERAL] Passing Array to Function ? From: Richard Lynch (richard <email protected>)
Date: 07/01/00

In article <3958595B.A3D27234 <email protected>>,
jack <email protected> (Jack Sasportas) wrote:

> I am having problems passing an array to a function.
> I could not find anything on the FAQ's or function info,although what I
> did find made it seem that you could pass an array to a function.
> I get parese errors....

function foo($array){
  //This function assumes you pass in an array.
  while (list($k, $v) = each($array)){
    echo "$k ==&gt; $v<BR>\n";
  }
}

$bar = array('a' => 'apple', 'b' => 'banana', 'c' => 'coconut');
foo($bar);

You're probably trying to indicate that the array is an array somehow in
the function header. Don't. PHP is value-typed, not variable-typed: An
array knows it's an array because it is an array, not because some
function header or variable declaration told it it was.

-- 
Richard Lynch                | If this was worth $$$ to you, buy a CD
US Customer Support Director | from one of the artists listed here:
Zend Technologies USA        | http://www.L-I-E.com/artists.htm
http://www.zend.com          | (this has nothing to do with Zend, duh!)

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>