php - using a variable as formula -


According to user input, I do a query and then do some math on the result. My problem is that I am accumulating math in one variable, and it can not be read as a mathematical form. For example:

  $ math = ($ ArryDBs [$ i] ['GSE45728_01'] + $ ArryDBs [$ i] ['GSE45728_02']) // This user input is created on echo Has been "& lt; table & gt;"; // It is coded after selection, where $ ArryDBs is generated for ($ i = 0; $ i <$ num_rows; $ i ++) {echo "<"> <; &;;; "Echo" from monastery & lt; Td> 1): "Monastery." & Lt; / Td> "; Direct:" ($ ArryDBs [$ i] ['GSE45728_01'] + $ ArryDBs [$ i] ['GSE45728_02']) "& lt; / td>" ;;;; & Lt; / Td> "; echo" & lt; / tr> ";} resonates" & lt; The output is as follows (note that the expression for 1) and 2) are the same):  
  1)   

From monastery: ($ ArryDBs [$ i] ['GSE45728_01'] + $ Eridibei [$ i] ['GSE45728_02']) 2) Direct: 8.23018 1) From monastery: $ $ ArryDBs [$ i] ['GSE45728_01'] $ $ [$ I] ['GSE 45728_02']) 2) Direct: 12.46399 1) From monastery: ($ ADEB [$ i] ['GSE 45728_01'] + $ RRDB [$ i] ['GSE 45728_02'] ) 2) Direct: 15.08 9 6

2 values) Direct what I want but it changes according to the user input This is the reason that I Why am I storing the expression in R, it means the meaning of the variable as a string. All related questions suggest using the eval (), although people (and manual itself) always discourage its usage. / P>

My question: How can I read $ Math as an operation to work?

PHP recursive is not executable. Can not embedded and can be expected to execute it on PHP.

E.g.

  & lt ;? php echo "hello "; ? & Gt;   

is going to be printed, literally:

  Hello   

If you want content of variable that is considered as "math" (such as php code), then you have to execute those content, such as

  php> $ Foo = "echo 1 + 1;"; Php & gt; eval ($ foo); 2   

And be aware that the content of the variable should be a valid php code. Calculates eval ('1 + 1') 2 , but is not assigned anywhere due to that value or is returned to anything, it Only the bus will be thrown.


Follow the comment:

  php> $ A = 1; Php & gt; $ B = 2; Php & gt; $ C = 3; Php & gt; $ D = 4; Php & gt; $ Foo = '$ bar = ($ a + $ b) * ($ c + $ d);'; Php & gt; eval ($ foo); Php & gt; Counterpart $ bar; 21   

Works as expected.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -