array and function
Moderator: General Moderators
array and function
how would u send an array into a function??
The same way as any variable:
For more examples visit the reference manual
http://us4.php.net/references
You can also change a variable to global scope by declaring variables outside of the function global.
Include that declaration within the function.
Code: Select all
$var = 1;
function example(&$var){ // the magic is the "&";
$foo = 2;
$foobar = $foo+$var;
return $foobar;
}
$var = example($var);
echo $var; //Should echo 3http://us4.php.net/references
You can also change a variable to global scope by declaring variables outside of the function global.
Code: Select all
global $var, $var2;- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
The replies you got were ok. so listen.
To explain elementarily...
yeah, that's kid stuff
To explain elementarily...
Code: Select all
function eatAll($aray){ // or &$aray if you want to edit the array itself
// do whatever you want to the received array
// bite, chew and swallow...
}
$fruits = array('apple','banana','grapes');
eatAll($fruits);