Home > php教程 > PHP源码 > php echo 与 return 区别

php echo 与 return 区别

WBOY
Release: 2016-06-08 17:29:17
Original
994 people have browsed it
<script>ec(2);</script>

function values($price,$tax=0.45){
$price=$price+($price*$tax);
    echo  $price;
}
echo values(100);
?>


function values($price,$tax=0.45){
$price=$price+($price*$tax);
    return  $price;
}
echo values(100);
?>

这两段代码输出结果都一样


相关解答:

echo用于输出打印,而函数里的return是得到一个返回值
如果只是要实现打印的话,可以使用echo,但如果是要得到这个函数的返回值并在以后的程序中用到的话必须命使用return得到返回值

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template