質問

I have the below code in php.

 function something($abc='abc', $bcd){
        echo $abc;
        echo $bcd;
    }
something('','Hi buddy');

Output I am getting

Hi buddy

I understand why I am getting it so, It is because the value I have sent for $abc is empty.

Is there any way in php to get the default value if the value is set empty, false, NULL, undefined

I am sorry if it looks silly. Till today I had thought that the empty value will be replaced with the default value assigned in the function.

any suggestions. thanks in advance.

役に立ちましたか?

解決

In order to get the default results, you need to call your function like this:

something(null, 'Hi buddy');

'' is not an empty parameter, it's just an empty string.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top