Here's a simple php function.
function hello($name) {
$message = 'Hello '.$name.' How are you feeling today?';
return $message;
}
And as you know, when I execute this function it returns a message.
<?php
echo hello(Stackoverflow);
?>
Output :
Hello Stackoverflow How are you feeling today?
Is there any way to display this message without using the echo (at least not here)
like <?php hello(Stackoverflow); ?> and it should return the message.
If that's the case, your function should have echo.
function hello($name) {
$message = 'Hello '.$name.' How are you feeling today?';
echo $message;
}
There are many ways to display something. printf is very useful in this case.
<?php
function hello($name){
printf('Hello %s How are you feeling today?', $name);
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With