I'm trying to access to variables in other files within a php function. outside of the function it brings the value that i want without problems but i don't know why if i try to access to the variable inside the php function, i can't access the value.
i have a file called name.php
<?php
$name1 = "aa";
$name2 = "bb";
?>
and in index.php i'm trying to access to the variables in name.php like this.
<?php
include_once('name.php');
echo $name1;
name();
function name(){
echo $name1;
}
?>
as i said i can print the name1 variable outside the function but not inside. can i know why and how to access to the variables in this case?
Thank you