AW: [PHP] How to use the fields of an array as individual parameter for a function
| From: | Christian Bartels | Date: | Tue, 04 Mar 2003 10:24:02 +0000 |
| Subject: | AW: [PHP] How to use the fields of an array as individual parameter for a function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138067@lists.php.net to get a copy of this message | ||
Ok, but how do i pass the vars to the second function (foo2)?
There is not a fixed number of parameters (and so fields in the $params
array).
---
Gruß
CB
-----Ursprüngliche Nachricht-----
Von: Jason Paschal [mailto:j_paschal@hotmail.com]
Gesendet: Dienstag, 4. März 2003 11:03
An: mailinglisten@thebartels.de
Betreff: Re: [PHP] How to use the fields of an array as individual parameter
for a function
there are all sorts of ways to get elements out of arrays. here's one:
if i don't know how many elements are in the array:
$numinarray = count($array); //gives me the number of elements in array for
($i=0;$i<$numinarray;$i++) {
$element = $array[$i];
echo "$element is in the array.";
}
there's also a for each loop, but the syntax escapes me
>From: "Christian Bartels" <mailinglisten@thebartels.de>
>To: <php-general@lists.php.net>
>Subject: [PHP] How to use the fields of an array as individual
>parameter
>for a function
>Date: Tue, 4 Mar 2003 10:52:26 +0100
>
>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
>
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail