0

As i have two files i have declared variable $msg["CE"] in config.php file and i am trying to access that variable in function of login.php page ...

config.php

<?php
   $msg["CE"] = "connection_error";
?>

login.php

<?php
include_once "config.php";

function myf()
{
 return $msg["CE"];
}

echo myf();
?>

Please help me how to access that msg["CE"]

1 Answers1

0

The variable is available in the file login.php. However, because you attempt to access the variable from within a function (of which you don't supply the variable as a parameter), you need to use the global keyword.

function myf() {
    global $msg; 
    return $msg["CE"];
}

You should take a look at the documentation for variable scope for PHP.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96