There are a few different ways to do this, e.g. with global variables, but I will not encourage that. The problem is, that $varA and $varB are local to your function and will be reset (effectively to 0), each time your function is called. So, in order to keep the old values between function calls, you can try to use static class members, like this:
class myfunc {
static private $varA = 0;
static private $varB = 0;
public function inc($paramA, $paramB) {
self::$varA += $paramA;
self::$varB += $paramB;
return array(self::$varA, self::$varB);
}
}
$increm = myfunc::inc(2,7);
echo $increm[0];
echo $increm[1];
$increm = myfunc::inc(4,5);
echo $increm[0];
echo $increm[1];
This will give you following output:
2
7
6
12
Alternatively you can keep your function, but still use static class members:
class MyGlobals {
static public $varA = 0;
static public $varB = 0;
}
function myfunc($paramA, $paramB) {
MyGlobals::$varA += $paramA;
MyGlobals::$varB += $paramB;
return array(MyGlobals::$varA, MyGlobals::$varB);
}
$increm = myfunc(2,7);
$increm = myfunc(4,5);
Hope that helps