看例1:<?php
function &returns_reference()
{
return $someref="哈只";
}$newref =& returns_reference();
echo $newref;
?>
例1:<?php
function returns_reference()
{
return $someref="哈只";
}$newref =returns_reference();
echo $newref;
?>为什么不要&号,输出的都是一样的结果,有谁能解释一下
function &returns_reference()
{
return $someref="哈只";
}$newref =& returns_reference();
echo $newref;
?>
例1:<?php
function returns_reference()
{
return $someref="哈只";
}$newref =returns_reference();
echo $newref;
?>为什么不要&号,输出的都是一样的结果,有谁能解释一下
<?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"
?>
<?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 "哈只";
}
返回值,和有没有变量根本无关,和加不加&更没有关系
你的例子是参数引用,跟返回值引用是两码事function &returns_reference()
{
return $someref="哈只"; //返回引用则$someref变量不会被unset,只有当这个变量不存在任何引用时才会被销毁。
}function returns_reference()
{
return $someref="哈只"; //返回值说明$someref变量在函数返回时会被unset
}