我有以下(汇总)代码
define pauls_code($a, $b)
{
$c = $a + $b;
echo $a;
echo $b;
}
pauls_code(1,2);
echo $c; // how do I get this to print outside of the function? I have tried everything. I am hoping to see 123
答案 0 :(得分:3)
使您的功能如下并返回$c
function pauls_code($a, $b){
$c = $a + $b;
return $c;
}
echo pauls_code(1,2);
答案 1 :(得分:0)
要在php中声明一个函数,您只需将function pauls_code($param1, $param2)
放入define
您无法在该功能之外访问$c
,请详细了解范围:http://php.net/manual/en/language.variables.scope.php