Declaring a global variable inside a function

前端 未结 7 1972
误落风尘
误落风尘 2020-12-03 01:15

I have two PHP files. In the first I set a cookie based on a $_GET value, and then call a function which then sends this value on to the other file. This is s

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 01:58

    you have to define the global var in the second function as well..

    // global scope
    $ref_id = 1;
    
    grabReferral($rid){
       global $ref_id;
       $ref_id = $rid;
    }
    
    someOtherFunction(){
        global $ref_id;
        sendValue($ref_id);
    }
    

    felix

提交回复
热议问题