Why does THIS not work when called via e.g. wd(1) (it always returns ‘-2’)?
$zoom=$user['zoom'];
function wd($hrs){
return $hrs*$zoom-2;
}
But THIS works fine:
function wd($hrs){
return $hrs*30-2;
}
Assuming this was a casting problem, I tried all sorts of variations like
(int)$hrs * ((int)$zoom)
or
(int)$hrs * (float)$zoom
but no success 🙁
Any help would be appreciated.
(And BTW, does it matter whether the function is located within
include('header.php')
— although I tried it both within and outside the header?)
EDIT: You should pass that variable as an argument to the function, but if you absolutely need to keep the variable global, do the following.
You need to bring the global into scope: