PHP:从函数返回值并直接回显它? [英] PHP: return value from function and echo it directly?

查看:147
本文介绍了PHP:从函数返回值并直接回显它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但... ...

php

 函数get_info(){
$ something =test;
返回$ something;
}

html $ b

 < div class =test><?php echo get_info(); ?>< / DIV> 

有没有办法让函数自动回显或打印返回的语句?
像我想这样做...

 < div class =test><?php get_info( ); ?>< / DIV> 

...没有回音吗?

有关于此的任何想法?

解决方案

您可以使用特殊标签:

 <?= get_info(); ?> 

或者,当然,您可以让您的函数回显该值:

 函数get_info(){
$ something =test;
echo $ something;
}


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!

解决方案

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;
}

这篇关于PHP:从函数返回值并直接回显它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆