|
Posted by Jason Barnett on 01/13/05 17:25
M. Sokolewicz wrote:
> Justin French wrote:
>
>> Hi all,
>>
>> Pretty sure this can't be done, but thought I'd ask any way...
>>
>> I have a function where the 3rd argument is an array..
>>
>> function foo($a,$b,$c) {
>> echo $a.$b;
>> print_r($c);
>> }
>>
>> Obviously the function does more than that, but anyway, I want the
>> calls to this function to look a little cleaner than this:
>>
>> foo("cat","dog",array("a"=>"1","b"=>"2","c"=>"3"));
Well you can always store the array in a variable and just pass the
variable to the function as the third parameter. At least it would look
prettier.
$vars = array("a"=>"1","b"=>"2","c"=>"3");
foo("cat","dog",$vars);
>>
>> is there any other way to define the array?
>>
>> foo("cat","dog",("a"=>"1","b"=>"2","c"=>"3")); or
>> foo("cat","dog",{"a"=>"1","b"=>"2","c"=>"3"}); would be nice (Ruby has
>> something like this), but I'm guessing it's not possible.
>
> nope, that's the only way
>
Well... I suppose that you could create an object and then treat the
object like an array (i.e. PHP5), but I doubt you want to do this unless
you have a specific purpose for using the object in this way.
>>
>> But, I'm asking just in case I've missed it in the docs.
>>
>> TIA
>>
>> ---
>> Justin French, Indent.com.au
>> justin.french@indent.com.au
>> Web Application Development & Graphic Design
--
Teach a person to fish...
Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2
[Back to original message]
|