Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
No, you have to pass the array as a parameter to the function:
PHP Code:
functionName($array)
You cannot call the function and expect it to have an array defined outside the function visible inside the function.
And in your example, arg1 and arg2 are just the elements of the array $foo.
If you call the function the way you wrote it, the arguments will always be the same.
If you would use your example, you would do
PHP Code:
$foo=array('arg1','arg2'); functionName($foo);
Or, if you want to name your parameters:
PHP Code:
function bar($pars){ foreach($pars as $key=>$val){ $$key=$val; //the name in $key is created as a variable with the value "$val" print("The parameter $key value is $val<br/>\n"); } } $foo=array('arg1'=>'val1','arg2'=>'val2'); bar($foo);
So no, you cannot use func_get_args(), you must iterate through the array given in parameter, like I showed you previously.
Which gives me:
Quote:
$:> php 3.php
The parameter arg1 value is val1<br/>
The parameter arg2 value is val2<br/>
$:>_
|
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 04-15-2010 at 10:24 AM..
|