N
N
NeTLeaDeR2018-03-16 19:40:56
PHP
NeTLeaDeR, 2018-03-16 19:40:56

How to calculate the value of an expression?

There is an input field in which formulas are entered (note 2*cos($rad)), $rad is calculated in the code, you need to assign the value of this expression to the $r variable. eval("$r=".$func.";"); it doesn't work like that, I don't know how to do it differently. (This value is calculated n times in a loop and $rad is always different, respectively). For personal use only, so the insecurity of eval is not important

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
riot26, 2018-03-16
@riot26

This is how it works ¯\_(ツ)_/¯

$rad = 0.5;
$formula = '2*cos($rad)';

eval('$r = ' . $formula . ';');
echo $r;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question