I have some code which looks something like this:
<?
$myvar = 3;
echo times_number($_GET['first'], $_GET['second']);
function times_number($number, $times_by = $myvar) {
$buf = $number * $times_by;
return $buf;
}
?>
the basic idea is that I need to set the "default" value of $times_by to a variable i have set previously (in this case $myvar)
problem is I get Parse Error in script.php on line (line number of function() )
if we substituted $myvar with it's value, we're fine (example code below)
<?
$myvar = 3;
echo times_number($_GET['first'], $_GET['second']);
function times_number($number, $times_by = 3) {
$buf = $number * $times_by;
return $buf;
}
?>
the above code works fine..
Is there any way to fix this parse error, so I can make my script work how it should.
the only way I can think of which could also work, but is longer than (i think) neccessary is:
<?
$myvar = 3;
echo times_number($_GET['first'], $_GET['second']);
function times_number($number, $times_by) {
global $myvar;
if(!$times_by)
$times_by = $myvar;
$buf = $number * $times_by;
return $buf;
}
?>
If anyone could help it'd be really appreciated!