Re: Variable Argument List

From: Date: Mon, 17 Nov 2008 17:57:12 +0000
Subject: Re: Variable Argument List
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-283379@lists.php.net to get a copy of this message
On Mon, 2008-11-17 at 11:54 -0500, Shiplu wrote: > On Fri, Nov 14, 2008 at 8:13 PM, Daniel Kolbo <kolb0057@umn.edu> wrote: > > Hello, > > > > I am trying to do something like the following: > > > > <?php > > > > function hello($var1 = 'default1', $var2 = 'default2') { > > echo "$var1:$var2"; > > } > > > > $func= "hello"; > > $args = "'yo','bob'"; > > $func($args); > > > > ?> > > > > I understand why this outputs: > > 'yo','bob':default2 > > However, I want it to output: > > yo:bob > > > > Is this possible? I tried using different combinations of {}, but I cannot > > seem to get it to happen. I need some kind of "preprocessor" feature > > perhaps. > > Its possible. use eval. > > eval("$func($args);"); If you used eval in the above statement (yes, you did) then you answered the problem incorrectly: <?php $func = 'hello'; $args = array( 'yo', 'bob' ); call_user_func_array( $func, $args ); ?> Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.general (#283379) next »