> Are there any hardcore PHP gurus out there that can help me with an
> unusual PHP construct (converting an array into a list of elements to pass
> as parameters into a function)?
>
> Please e-mail me privately. Thanks!
Sellam;
I'm not a php programmer, but I sit next to a large team of incredibly good
PHP programmers. They are thinking the PHP function you want is "list". This
will take an array and assign the array members to variables. Then you can
call your function with those variables. If the number of elements in the
array is always variable/unknown, you may have a problem with this approach.
But it depends on if the unknown number of array elements is huge or small,
and how important later members of the array are (ie. is it ok of they are
lost). Let me clarify with an example.
Example : Lets say you know that there are 3 elements in your array. You can
assign them to individual variables as follows:
list($first,$second,$third) = array(1,3);
Then you can call your function with the parameters $first, $second, $third,
etc.
Now for the gotchas that occur when you don't know how many values are going
to be in the array (ie. it's not always constant). If your array is fairly
small as to number of elements, you can simply use the above construct and
pass ALL array elements to the list function, and then hard code all those
variables to pass to your function. However, your function will have to look
at each variable, and stop when the particular parameter is null/undefined.
If your array is dimensioned fairly small, the code would not look messy
really and this would be a fine approach. But if you have 50 or a 100
elements in your array the code would be really icky-looking. But note that
if you have less variables specified in your list function than the array
members specified on the right hand side, those array variables are silently
ignored in the assignment.
Ok, now if I could just find someone on the list to help me with a
libtool/automake problem I'm having... :)
Jay West
---
[This E-mail scanned for viruses by Declude Virus]
Received on Fri May 14 2004 - 08:27:54 BST