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.
)
The code is as follows
|
Copy code
|
function results($string)
{
$result = array();
$result[] = $string;//Original string
$result[] = strtoupper($string);//Change all to uppercase
$result[] = strtolower($string);//Change all to lowercase
$result[] = ucwords($string);//Change the first letter of the word to uppercase
return $result;
}
$multi_result = results('The quick brown fox jump over the lazy dog');
print_r($multi_result);
?>
Output 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
)
Quote
The code is as follows
|
Copy code
|
test(&$a,&$b){
$a = 1000;
$b = 12000;
Return $a+$b;
}
$a = 10;
$b = 12;
$c = test($a,$b); //Note that there is no & here.
//Show the modified value
echo $a;
echo $b;
echo $c; //This is the function return value;
http://www.bkjia.com/PHPjc/629017.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629017.htmlTechArticleThe return value of the 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 will cause the program to stop at return and return...
|
|