PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<函数的参数变量函数>
Last updated: Mon, 16 Jul 2012

返回值

值通过使用可选的返回语句返回。任何类型都可以返回,其中包括列表和对象。 这导致函数立即结束它的运行,并且将控制权传递回它被调用的行。更多信息 请参照 return()

例子 17-9. return() 函数的用法

<?php
function square ($num)
{
   return
$num * $num;
}
echo
square (4);  // outputs '16'.
?>

函数不能返回多个值,但为了获得简单的结果,可以返回一个列表。

例子 17-10. 返回一个数组以得到多个返回值

<?php
function small_numbers()
{
   return array (
0, 1, 2);
}
list (
$zero, $one, $two) = small_numbers();
?>

从函数返回一个引用,你必须在函数声明和指派返回值给一个变量时都使用引用操作符 & :

例子 17-11. 由函数返回一个引用

<?php
function &returns_reference()
{
   return
$someref;
}

$newref =& returns_reference();
?>

有关引用的更多信息, 请查看 引用的解释.




<函数的参数变量函数>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST