1

I have the following (summarised) code

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
Greg
  • 9,068
  • 6
  • 49
  • 91

2 Answers2

3

make your function like this and return the $c

function pauls_code($a, $b){
$c = $a + $b;
return $c;
}
echo pauls_code(1,2);
Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
0

To declare a function in php you simply put function pauls_code($param1, $param2) not define

You can not access $c outside of the function, read more about scope: http://php.net/manual/en/language.variables.scope.php