PHP works outside function but wont work inside function

前端 未结 1 518
臣服心动
臣服心动 2021-01-29 12:58

I\'m trying to put the following code into a function as I need to use it quite a few times but with one variable changed ($subject) but it doesn\'t seem to be working. If I rem

相关标签:
1条回答
  • 2021-01-29 13:16

    $connect is no longer accessible inside the function. A simple, but bad fix would be this:

    function count($subject){
        global $connect
    

    A better fix would be for you to send in the $connect variable to the function:

    function count($subject, $connect){
    

    And change your function calls to

    count("The subject", $connect)
    
    0 讨论(0)
提交回复
热议问题