标签:变量 运算 异常 comm rabbitmq 代码 异常处理 正则表达 and
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
<?php
function add_some_extra(&$string)
{
$string .= ‘and something extra.‘;
}
$str = ‘This is a string, ‘;
add_some_extra($str);
echo $str; // outputs ‘This is a string, and something extra.‘
?>
<?php
function sum(...$numbers) {
$acc = 0;
foreach ($numbers as $n) {
$acc += $n;
}
return $acc;
}
echo sum(1, 2, 3, 4);
?>
#可以使用默认参数
function myfun($myvar="Moments") {
}
#按值传递
function myfun($myvar){
$myvar = "Moments";
}
$myvar = "Hello World!";
myfun($myvar);
echo $myvar;
#输出的结果为Hello World!
#引用传递
function myfun(&$myvar){
$myvar = "Moments";
}
$myvar = "Hello World!";
myfun($myvar);
echo $myvar;
#输出的结果为Moments
标签:变量 运算 异常 comm rabbitmq 代码 异常处理 正则表达 and
原文地址:http://www.cnblogs.com/myall/p/7145412.html