Hi,
Tuesday, March 4, 2003, 7:52:26 PM, you wrote:
CB> Hello!
CB> I'm new here on the list. I hope you can help me! :)
CB> I have a function foo1 which has a parameter $params. In the function i want
CB> to pass $params to another function foo2. if $params is an array the
CB> elements should be passed to foo2 as individual parameters. Is this
CB> possible? How do i do that?
CB> Example:
CB> function foo1($params) {
CB> if (is_array($params)) {
CB> $object = new foo2(GET THE ELEMENTS OF $params AS INDIVIDUAL PARAMETERS
CB> HERE);
CB> } else {
CB> $object = new foo2($params);
CB> }
CB> }
CB> So when this is called:
CB> foo1(array('blue', 'red', 'green'));
CB> In foo1 foo2 should be called like this:
CB> foo2('blue', 'red', 'green');
CB> Is this possible?
CB> Thanks for any help!
CB> (sorry about my english ;-))
CB> ---
CB> CB
CB> --
CB> PHP General Mailing List (http://www.php.net/)
CB> To unsubscribe, visit: http://www.php.net/unsub.php
You could use eval, something like this:
$num = count($params);
$vars = '$subject = new foo2(';
if($num > 0) {
$i = 0;
foreach($params as $var){
$vars .= ($i > 0)? ',':'';
$vars .= (is_string($var))? "'".$var."'" : $var;
$i ++;
}
}
$vars .= ');';
eval($vars);
untested but is similar to something I use as a class loader with
unknown number of variables to pass.
--
regards,
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php