PHP: Global variable scope

前端 未结 5 541
天命终不由人
天命终不由人 2020-12-22 12:26

I have a separate file where I include variables with thier set value. How can I make these variables global?

Ex. I have the value $myval in the v

5条回答
  •  悲哀的现实
    2020-12-22 13:03

    Using the global keyword in the beginning of your function will bring those variables into scope. So for example

    $outside_variable = "foo";
    
    function my_function() {
       global $outside_variable;
       echo $outside_variable;
    }
    

提交回复
热议问题