Assuming the following code:
change function doStuff($rowCount)
to function doStuff(&$rowCount)
Normally in PHP you're sending a copy of the variable to the function, so modifications within the function will not affect the value of the variable outside of the function. Adding the ampersand tells PHP to send a reference to the variable instead so modifications to the variable propagate back to the caller.