I need an help to understand this problem I am facing...and apologies if it seems silly.
I wrote a function that makes some calculations according to two differents dates (arrival and departure). It all works fine, the returned values is given and it is correct.
Nevertheless while this calculation is made there is variable created ($days) which I would like to use (echo) outside the function. I have tried to make it global but I get an error...guessing that I am on the wrong path!
So my question is how do you get a value inside a function other than the returned value? if it is at all possible of course.
code below:
function costs($date1, $date2, $price) {
$arr= explode("/", $date1);
$timestamp1 = mktime(0,0,0,$arr[1],$arr[0],$arr[2]);
$arr2= explode("/", $date2);
$timestamp2 = mktime(0,0,0,$arr2[1],$arr2[0],$arr2[2]);
$timestamp = $timestamp2 - $timestamp1;
$days = $timestamp/86400;
$cost = $days * $price;
return $cost;
}
Appreciated any little help to understand this. Francesco