RE: null as function argumnent?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bas Jobsen wrote:
> Hi,
> 
> I want to use a ?: statement. If not true de default function
> argument have to be used. How to do this
> 
> <?
> function test($test='default')
> {
> echo $test;
> }
> test(($value==1)?'no default':null);
>> 
> 
> What do i have to pass instead of null to get default print?

Try this:

function test($test = null) {
  if (is_null($test)) { $test = 'default'; }
  echo $test;
}

test(($value == 1) ? 'no default' : null);

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux