Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top