Well, Tom Rogers already posted this solution and it works great:
$num = count($params);
$vars = '$object = new foo2(';
if($num > 0) {
$i = 0;
foreach($params as $var){
$vars .= ($i > 0)? ',':'';
$vars .= (is_string($var))? "'".$var."'" : $var;
$i ++;
}
}
$vars .= ');';
eval($vars);
---
Gru�
CB
-----Urspr�ngliche Nachricht-----
Von: Dimitris Kossikidis [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 4. M�rz 2003 12:18
An: [EMAIL PROTECTED]
Betreff: [PHP] Re: How to use the fields of an array as individual parameter
for a function
I suppose that argc & argv variables should be supported in future releases
of php. At this time only cgi php supports this feature. Am i wrong?
"Christian Bartels" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hello!
I'm new here on the list. I hope you can help me! :)
I have a function foo1 which has a parameter $params. In the function i want
to pass $params to another function foo2. if $params is an array the
elements should be passed to foo2 as individual parameters. Is this
possible? How do i do that?
Example:
function foo1($params) {
if (is_array($params)) {
$object = new foo2(GET THE ELEMENTS OF $params AS INDIVIDUAL PARAMETERS
HERE);
} else {
$object = new foo2($params);
}
}
So when this is called:
foo1(array('blue', 'red', 'green'));
In foo1 foo2 should be called like this:
foo2('blue', 'red', 'green');
Is this possible?
Thanks for any help!
(sorry about my english ;-))
---
CB
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php