Skip to content
Advertisement

function optional properties in php

I have one function by 2 optional property and how send value hight?

function test($size=1,$hight=2){
// code .........
}
 test($hight)
 test(null,$hight);

Is there any other way? I dont need test(null,$hight);

Advertisement

Answer

You can use like it, May be it will help to you.

function test($hight=null,$size=null){
 // code .........
}
$hight = 2;
$size = 1;
test($hight)
test($hight,''); // if you pass as '' - blank even it's work and if second parameter is not given even it will work.
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement