echo 没有返回值
print 有
//你可以
1 && print 1;
//不可以
1 && echo 1;

解决方案 »

  1.   

    PHP里的输出最常用的是echo,print.两者都不是真正的函数,而是语言构造,所以调用时不必用双括号(比如echo("test");print("test")).在输出的时候两者都可以实现赋值: 
    PHP:  
    echo $str="test"; //一方面输出test,一方面把"test"赋给字符串变量 $str 
    print $str="test";  
    两者除了名字不一样外,还是有其它区别的。print具有返回值,一直返回1,而echo没有,所以echo比print要快一些: 
    PHP:  
    $return = print "test"; 
    echo $return; // 输出1  
    也正因为这个原因,print能应用于复合语句中,而echo不能: 
    PHP:  
    isset($str) or print "str 变量未定义"; // 将输出"str 变量未定义" 
    isset($str) or echo "str 变量未定义";// 将提示分析错误  
    echo一次可输出多个字符串,而print则不可以: 
    PHP:  
    echo "i ","love ","iwind"; // 将输出 "i love iwind" 
    print "i ","love ","iwind"; // 将提示错误  
    echo,print还可以输出被称作“文档句法”的字符串,句法如: 
    PHP:  
    echo <<< 标签名称 
    ... 
    字符串内容 
    ... 
    标签名称;  
    比如 
    PHP:  
    echo <<< test 
    i love iwind 
    test;  
    要注意的是语句开始和结束的两个标签名称是一样的,且后一个标签名称前不能有空白,即要顶格写。文档句法输出的内容识别变量名称和常用符号,大致形同双引号的作用。
      

  2.   

    本质的区别: echo 不属于函数
      

  3.   

    print也不是函数,他们都属于语言结构,你知道语言结构是什么概念吗?和函数有什么区别?
      

  4.   

    楼上说的对,print也不是函数.
    下面是在php官方看到的一些,
    连接:http://cn.php.net/manual/zh/function.echo.php#55259lorenpr at gmail dot com
    28-Jul-2005 05:17 
    I just want to point out something to beginners. The documentation is misleading where it says:// Because echo is not a function, following code is invalid.
    ($some_var) ? echo 'true' : echo 'false';The code is invalid, but not because 'echo' is a language construct, but rather because 'echo' does not return a value. 
    So don't be mislead: the syntax used above is certainly not limited to functions.You must keep in mind that the job of the ternary syntax used is not actually to display anything, but to test a boolean relationship. The 'print' statement would work because it always returns a 1, which in php, is interpreted to a boolean  'true'. Things that return 'void' cannot be expected to evaluate to a 'true' or 'false', and that is why using 'echo' in this particular case is invalid.
      

  5.   

    都是语言结构而不是函数
    只是print有返回值而已
      

  6.   


    echo一次可输出多个字符串,而print则不可以: 
    PHP: 
    echo "i ","love ","iwind"; // 将输出 "i love iwind" 
    print "i ","love ","iwind"; // 将提示错误