您的位置:首页 > 其它

echo与print的共同和区别

2009-04-18 14:19 190 查看
共同

1.都不是函数,只是语言结构

2.都只是输出string,init等简单类型

<?php
echo array('test');
print array('test');
?>
output:
ArrayArray


<?php
class Test {
	
}
$oTest = new Test();
echo $oTest;
print $oTest;
//都将导致解析错误
?>




用例子来说没区别所在。

1.echo无返回值,print有。

<?php
$ret = echo('test');//这是语法错误
$ret = print('test');//返回值为1
?>


所以echo的速度要比print快

2用法区别 echo可以输出多个string ,print只能一个

<?php
echo 'test1','test2';//输出'test1test2';
print 'test','test2';//语法错误
?>


3.print 的用法更像函数

<?php
2 ? print 'test1' : print 'test2';//输出'test1';
2 ? echo 'test1' : echo 'test2';//语法错误
?>


3.@的使用 print 可以@print 当时echo 不可以

<?php
@echo $c;//语法错误
@print $c;
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: