By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,515 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,515 IT Pros & Developers. It's quick & easy.

Passing arrays to functions

P: n/a
OK, another quickie,
How do I pass an array to a function? This is what I have, and the second
function doesn't seem to be getting the array somehow. I'm sure it's in
the function declaration...

function one(){
return $array; // yes, there is more to this function, and assume that
"$array" is a real array
}

funtcion two($arrayArg){ // <- I'm sure the prob is here.
print_r($arrayArg); // This isn't printing anything, when it does in one()
}

then I call:
two(one());
Once again, I'm sure the prob is in the declaration.

Thanks in advance,
-Eric Kincl
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Eric Kincl wrote:
OK, another quickie,
How do I pass an array to a function? This is what I have, and the second
function doesn't seem to be getting the array somehow. I'm sure it's in
the function declaration...

function one(){
return $array; // yes, there is more to this function, and assume that
"$array" is a real array
}

funtcion two($arrayArg){ // <- I'm sure the prob is here.
print_r($arrayArg); // This isn't printing anything, when it does in one()
}

then I call:
two(one());
Once again, I'm sure the prob is in the declaration.


I don't think that the declaration is the problem... For instance, try
this code:

<?php
function one(){ return array(1=>'one',2=>'two',5,'me too!'); }
function two($ar){ print_r($ar); };

$myVar=one();
two($myVar);

two(one());
?>

Results:
Array
(
[1] => one
[2] => two
[3] => 5
[4] => me too!
)
Array
(
[1] => one
[2] => two
[3] => 5
[4] => me too!
)

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.