this might be a stupid question but …
php
function get_info() {
$something = "test";
return $something;
}
html
<div class="test"><?php echo get_info(); ?></div>
Is there a way to make the function automatically "echo" or "print" the returned statement? Like I wanna do this …
<div class="test"><?php get_info(); ?></div>
… without the "echo" in it?
Any ideas on that? Thank you in advance!
Definition and Usage The echo() function outputs one or more strings. Note: The echo() function is not actually a function, so you are not required to use parentheses with it. However, if you want to pass more than one parameter to echo(), using parentheses will generate a parse error.
They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions.
Values are returned by using the optional return statement. Any type may be returned, including arrays and objects. This causes the function to end its execution immediately and pass control back to the line from which it was called.
Echo is for display, while return is used to store a value, which may or may not be used for display or other use.
You can use the special tags:
<?= get_info(); ?>
Or, of course, you can have your function echo the value:
function get_info() {
$something = "test";
echo $something;
}
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