Home > Backend Development > PHP Tutorial > Return value of php function_PHP tutorial

Return value of php function_PHP tutorial

WBOY
Release: 2016-07-13 17:14:04
Original
1219 people have browsed it

Return value of php function. In fact, the PHP function can return one or more values, and the return keyword can be used to return a variable or an array. return causes the program to stop at return and return the specified variable.

Let’s give an example today:

The code is as follows
 代码如下 复制代码

';
function she($a,$b,$c)
{
   return array($c,$b,$a);
}
list($x,$y,$z)=she(2,3,4);
echo '$x='.$x.'$y='.$y.'$z='.$z;
?>
执行结果如:

function add($shu)
{
return $shu+1;
}
echo add(2).'
‘;

function she($a,$b,$c)
{
return array($c,$b,$a);
}
list($x,$y,$z)=she(2,3,4);
echo ‘$x=’.$x.’
$y=’.$y.’
$z=’.$z;
?>

php函

Copy code

';
function she($a,$b,$c)
{
Return array($c,$b,$a);
}
list($x,$y,$z)=she(2,3,4);
echo '$x='.$x.'$y='.$y.'$z='.$z;
?>
The execution result is as follows:

 代码如下 复制代码

function results($string)
{
$result = array();
$result[] = $string;//原字符串
$result[] = strtoupper($string);//全部换成大写
$result[] = strtolower($string);//全部换成小写
$result[] = ucwords($string);//单词的首字母换成大写

return $result;
}
$multi_result = results('The quick brown fox jump over the lazy dog');
print_r($multi_result);
?>

输出结果:
Array
(
[0] => The quick brown fox jump over the lazy dog
[1] => THE QUICK BROWN FOX JUMP OVER THE LAZY DOG
[2] => the quick brown fox jump over the lazy dog
[3] => The Quick Brown Fox Jump Over The Lazy Dog
)

function add($shu)
{
return $shu+1;
}
echo add(2).'
‘;

function she($a,$b,$c)
{
return array($c,$b,$a);
}
list($x,$y,$z)=she(2,3,4);
echo ‘$x=’.$x.’
$y=’.$y.’
$z=’.$z;
?>

php letter
 代码如下 复制代码

test(&$a,&$b){
   $a = 1000;
   $b = 12000;
   return $a+$b;
}

$a = 10;
$b = 12;

$c = test($a,$b);   //注意这里没有 & 了。

//显示修改后的值
echo $a;
echo $b;      
echo $c;  //这是函数返回值;

Number, if you want to return multiple return values, how to do it (the function cannot return multiple values, but you can get a similar effect by returning an array.

)
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template