Page 1 of 1

calling a function from within a function?

Posted: Fri Nov 22, 2002 6:07 am
by martincrumlish
Hi,

I am working on a bet calculator and have got some help here regarding it before.

I wont go into details of the betting part of the problem just the PHP one.

Basically, I need to call a function from within another function and still return the value to the main PHP script.

Code: Select all

function doublecalc($odds1, $odds1a)
{
   if(($status1 == "win") && (($status2 == "void")) 
     {
	//the call to the other function
        $total = singlecalc($odds1, $odds1a, $stake, $rf1, deadheat1, $eachway1, $status1);
	$unitstake = $stake;
	}
	else{
	if(($status1 == "win") && ($status2 == "win")) 
	{
        do the normal function code
        }
return $total;
}
This is a function that will check the values passed and if 2 of the values passed are of a certain value control will go to the other function which will then carry out the calculations (singlecalc)

Any help with this is much appreciated.
Thanks,
Martin

Posted: Fri Nov 22, 2002 7:06 am
by mydimension
what exactly seems to be your problem?

Posted: Fri Nov 22, 2002 7:58 am
by BDKR
Hey,

I'm going to ask a couple of question. You can lie back on a couch now if you wish.

1) What becomes of $unitstake? I know that may not be important so don't bother answering if you don't want to.

2) I'm not following 100%, but I gather you want singlecalc() to return your total if that first condition is met. Is this correct? If that's the case, why not do something like

Code: Select all

return singlecalc($args);
But then that brings us back to the first question. Is $unitstake supposed to be some kind of global? Same with $stake? I don't see mention of either of these two anywhere else in the function.

Now this may not be warranted, but here goes. Why not do something like...

Code: Select all

if(condition1==true)
    { $total=singlecalc($args); }
else
    { $total=doublecalc($args); }
Also, all of those args that are passed to singlecalc() (one of which I just noticed is $stake 8O DOH !) except for $odds1 and $odds1a are coming from where? If you don't include these are args in the original function declaration, make them globals.

Anyways, since $unitstake is important in some way, doing things the way I suggested may be easier as you don't have to worry about returning $total AND $unitstake from the function. It can be done, but's easier as above. Just tweak it a little as such...

Code: Select all

if(condition1==true)
    { 
    $total=singlecalc($args); 
    $unitstake=$stake;
    }
else
    { $total=doublecalc($args); }
Anyways, I hope the rambling gives you some ideas. I'm not a code God or anything. Check Volka or Twig for that.
:D

Cheers,
BDKR