Assuming the following code:
You either have to assign the return value of the doStuff
calls back to the local $rowCount
variable:
$rowCount = 1;
echo $rowCount.' and ';
$rowCount = doStuff($rowCount);
$rowCount = doStuff($rowCount);
$rowCount = doStuff($rowCount);
Or you pass the variable as a reference by putting a &
in front of the formal parameter $rowCount
:
function doStuff(&$rowCount) {
$rowCount++;
echo $rowCount.' and ';
return $rowCount;
}
Now the formal parameter $rowCount
inside the function doStuff
refers to the same value as the variable that is passed to doStuff
in the function call.