看例1:<?php
function &returns_reference()
{
    return $someref="哈只";
}$newref =& returns_reference();
echo $newref;
?>
例1:<?php
function returns_reference()
{
    return $someref="哈只";
}$newref =returns_reference();
echo $newref;
?>为什么不要&号,输出的都是一样的结果,有谁能解释一下

解决方案 »

  1.   

    无论是传值还是传引用,php给echo的都是变量的值你的示例并不能解释引用的传递
      

  2.   

    &表示返回的类型是地址类型吧!PHP是弱语言!对于原因也不太清楚,希望有人能回答!
      

  3.   

    引用就是引用,值就是值,是有区别的,以下是引用的例子:
    <?php
    $someref = '';
    function &returns_reference()
    {
        global $someref;
        return $someref="hello";
    }$newref =& returns_reference();
    echo $newref; // 返回"hello"
    $someref = "world";
    echo $newref; // 返回"world"
    ?>以下是返回值的例子:
    <?php
    $someref = '';
    function returns_reference()
    {
        global $someref;
        return $someref="hello";
    }$newref =returns_reference();
    echo $newref; // 返回"hello"
    $someref = "world";
    echo $newref; // 返回"hello"
    ?>
      

  4.   

    /**********返回值*************/
    <?php
    $someref="哈哈哈只";
    function returns_reference ( $someref )
    {
        $someref="哈只";
    }
    returns_reference ( $newref ) ;
    echo "newref:".$newref."<br />\n";
    echo "someref:".$someref."<br />\n";
    ?>/*************返回引用*************/
    <?php
    $someref="哈哈哈只";
    function returns_reference ( &$someref )
    {
        $someref="哈只";
    }
    returns_reference ( $newref ) ;
    echo "newref:".$newref."<br />\n";
    echo "someref:".$someref."<br />\n";
    ?>
    /*********你写的相当于********/function returns_reference()
    {
      return "哈只";
    }
    返回值,和有没有变量根本无关,和加不加&更没有关系
      

  5.   

    TO fredyj(醉爱酸奶):
    你的例子是参数引用,跟返回值引用是两码事function &returns_reference()
    {
        return $someref="哈只"; //返回引用则$someref变量不会被unset,只有当这个变量不存在任何引用时才会被销毁。
    }function returns_reference()
    {
        return $someref="哈只"; //返回值说明$someref变量在函数返回时会被unset
    }