currently I have the following code
inside my 'function.php' is
function calcTime($database_name,$currentTime){
global $startTime;
global $endTime;
...calcutions
return $startTime;
return $endTime;
}//end calcTime()
inside my main 'index.php' I have
include('/function.php');
$databaseName = foo;
$currentTime = 12.30;
function begin($database_name,$currentTime){
...some calculations
calcTime($database_name,$currentTime); //calling the function from other file
echo $startTime;
echo $endTime;
}// end begin()
The problem I am having is that the variables that are declared inside the inner function do not pass through to the outer function. I have declared the variables globals and returned them. Not sure whats going on.
something interesting though, if I echo calcTime($database_name,$currentTime); the $startTime is returned but not $endTime.
Please help. I have functions that are used throughout other functions that I would like to use in this fashion. Thank you!!
globalbut at least I know that you do not have to return what’s global, or do not have to set global, what you return. I think (that’s where I am uncertain) thatglobalis used when you have a variable that already exists in the outer code before you use it inside a function. But in your code $startTime is not used before the function call. Just uselist($startTime, $endTime) = calcTime($database_name,$currentTime);and remove the twoglobalcommands. And of course change the tworeturntoreturn array($startTime, $endTime);