Hi
I'm fairly new to php and I am trying to figure how do I set an optional parameter after the first optional parameter?
For example I have the following code:
function testParam($fruit, $veg='pota',$test='default test'){
echo '<br>$fruit = '.$fruit;
echo '<br>$veg = '.$veg;
echo '<br>Test = '.$test;
}
If i make the following calls:
echo 'with all parama';
testParam('apple','carrot','some string');
//we get:
//with all parama
//$fruit = apple
//$veg = carrot
//Test = some string
echo '<hr> missing veg';
testParam('apple','','something');
//we get:
//missing veg
//$fruit = apple
//$veg =
//Test = something
echo '<hr> This wont work';
testParam('apple',,'i am set');
I want to try make a call so that in the last example I show 'pota' as the default $veg parameter but pass into $test 'i am set'.
I guess I can pass 0 into $veg then branch it in the code to say if $veg =0 then use 'pota' but just wondered if there's some other syntax as i cant find anything in php.net about it.