There is a big difference between the two actually... due to the nature of double and single quotes with variables.
The first one:
$originalStatFormula = '(&Stat1/&Stat2)';
$evalStatFormula =
'$theStatFormula = \''.str_replace('&','$',$originalStatFormula)."';";
eval($evalStatFormula);
Is actually perfoming this:
$theStatFormula = '($Stat1/$Stat2)';
Single quotes around variables makes them NOT evaluate. So you get the result of:
($Stat1/$Stat2)
The second one:
$originalStatFormula = '(&Stat1/&Stat2)';
$evalStatFormula =
'$theStatFormula = "'.str_replace('&','$',$theStatFormula).'";';
eval($evalStatFormula);
Is actually perfoming this:
$theStatFormula = "($Stat1/$Stat2)";
Double quotes around variables makes them DO evaluate. So you get the result of:
(5/2)
Now, you want to actually get the value of that ? What 5 divded by 2 is? Ok, then use this third way instead:
$originalStatFormula = '(&Stat1/&Stat2)';
$evalStatFormula =
'$theStatFormula = '.str_replace('&','$',$theStatFormula).';';
eval($evalStatFormula);
Is actually perfoming this:
$theStatFormula = ($Stat1/$Stat2);
Which will result in the answer being stored into $theStatFormula.
See, its all a sticky situation with them single and double quotes. Total different behavior happens depending on what you do with them. The whole reason I have the "eval()" function in the mix, is because you wanted to take the formula, and turn it into something that executes with variable names. Since variable names get stored inside the string, you have to 'execute' the string somehow. but to get a result, you build the full PHP line code to do it (includeing the semicolon at the end). "eval()" is a really fun function once you get to know it... it can allow for some seriously dynamic coding, like this case you are doing with custom built and executed formulas!
Hope this is a bit more clear? I'm sorry I didnt break this up like this before... was sort of in a rush.