Re: Feature?
| From: | Steve Cayford | Date: | Tue, 25 Sep 2001 14:36:57 +0000 |
| Subject: | Re: Feature? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-68713@lists.php.net to get a copy of this message | ||
Maybe this? A bit verbose, but functional.
-Steve
<?php
function foo($p)
{
if (empty($p['fred'])){
$p['fred'] = 'hello';} if (empty($p['banana'])){
$p['banana'] = 'world';} echo $p['fred'] . $p['banana']; } foo(array('fred' => 'hello', 'banana' => 'world')); ?> On Tuesday, September 25, 2001, at 06:25 AM, Andrey Hristov wrote:
Yeap, I know that. I thought about this bit of hack but this breaks the conception on giving parameters. Also this trick cannot solve the problem with default parameters. If I have function with 5 params and all of them have default values and I want to pass value only to the second parameter what I have to do? Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS ----- Original Message ----- From: <php@alister.dnsalias.com> To: "Andrey Hristov" <ahristov@icygen.com> Sent: Tuesday, September 25, 2001 1:14 PM Subject: Re: [PHP] Feature?On Tue, 25 Sep 2001 11:36:25 +0300, you wrote:-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.netIn the case when I've few parameters I've to remember their order, so why not $bar=foo('par2'=>10); I want to pass value to only one or more but not to all params. Also this will make the code clearer I think. Comments are welcome!<?php function foo($p) { echo $p['fred'] . $p['banana']; } foo(array('fred' => 'hello', 'banana' => 'world')); ?>