How to calculate math expression from in string with PHP

1 Answer

0 votes
$str = "17-2.1+3.3*4-0.5";

$result = eval('return ' . $str . ';');

echo $result;



/*
run:

27.6

*/

 



answered Jul 29, 2024 by avibootz
...