This is about RAW php coding. I have a page – “config.php” and there are some declarations here.
//config.php
<?php
$myvalue = "This is a test";
include("functions.php");
?>
//functions.php
<?php
function testFunction()
{
$dd = $myvalue;
echo $dd;
}
?>
And when I call “testFunction()” from another page like “page.php” I want it to echo “This is a test”. How can I do this? “config.php” is included to “page.php”. Hope the scenario is understandable.
//page.php
<?php
include('config.php');
testFunction();
?>
In the first line of your function, add:
Your
$myvalue-variable is transfered intofunctions.phpwhen you include that php-file after declaring the variable, but you have to tell your function to use this global variable.Your function would look like this: