I have tried to use the search function for a solution to my use case but I wasn't able to find a similar situation like mine. Please kindly help me on this.
I am currently developing a webpage that reads from 2 text files with names and numbers inside into different arrays. For ease of explanation, let's say:
$namesarray = array("x","y");
$valuesarray = array("3","2");
I also have a separate array that carries formulas imported from a text file like this:
$formulaname = array("data1","data2");
$formula = array("x+2","x+y");
So in math terms, the formulas could be written as:
data1 = x+2
data2 = x+y
What I would like to do is to do calculations like this when I call data2:
$data2 = $x + $y;
I'd like php to automatically use 3 and 2 for x and y respectively for the formula although the formula does not have any $ sign to denote x and y as variables.
Would such a situation be possible? I have looked into matheval and eval but I'm not too sure if they could be used for my situation.
Thank you for any assistance. :)