lundi 22 mai 2017

Is it possible to create a PHP function which can both display and return?

Is it possible to create a PHP function which can both display and return (Only one thing per time according how I called it)? Please look at the example.

Ex:

public function test_function(){
    echo "Hello"; // echo or anything......
}

If I called it test_function() it should display "Hello"; If I use it like $name = test_function(); $name should be equal to "Hello".

Note : I know that passing another parameter and using if condition I can do this. I am looking for more quick way if there is something like that.

Aucun commentaire:

Enregistrer un commentaire