PHP: return value from function and echo it directly?

前端 未结 7 1582
遇见更好的自我
遇见更好的自我 2020-12-31 05:44

this might be a stupid question but …

php

function get_info() {
    $something = \"test\";
    return $something;
}
<
7条回答
  •  孤独总比滥情好
    2020-12-31 06:35

    One visit to echo's Manual page would have yielded you the answer, which is indeed what the previous answers mention: the shortcut syntax.

    Be very careful though, if short_open_tag is disabled in php.ini, shortcutting echo's won't work, and your code will be output in the HTML. (e.g. when you move your code to a different server which has a different configuration).

    For the reduced portability of your code I'd advise against using it.

提交回复
热议问题