PHP: pass a variable to a function, do something to the variable, return it back

前端 未结 5 1912
孤街浪徒
孤街浪徒 2021-01-22 11:39

Assuming the following code:



        
5条回答
  •  离开以前
    2021-01-22 12:16

    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.

提交回复
热议问题