php - Concatenating characters/numbers to represent variables in Javascript? -
I have three PHP variables in this script which I want to use to get javascript for testing purposes. $ Q1, $ Q2 and $ Q3 respectively I want to output all of them to Que and their index (1, 2 and 3) together for loop one by one. East. If I want to produce $ Q2 at the second instance for parse, then it should be like 'Q' + i, where I am 2.
See below:
& lt ;? Php error_reporting (E_ALL); Ini_set ('display_errors', 'on'); $ Q1 = 'Q1'; $ Q2 = 'Q2'; $ Q3 = 'Q3'; ? & Gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Script type = "text / javascript" & gt; Var Q1 = "& lt ;? Php Print ($ Q1) ;? & gt;"; Var Q2 = "& lt ;? Php Print ($ Q2);? & Gt;"; Var Q3 = "& lt ;? Php Print ($ Q3) ;? & gt;"; For (var i = 1; i & lt; = 3; i ++) {warning (eval ("Q" + i)); } & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;
I tried to use eval but I think it is more for arithmetic purposes. What can I use to change it?
Why not use an array ?, you can loop over here to generate Php questions
& lt ;? Php error_reporting (E_ALL); Ini_set ('display_errors', 'on'); $ Q1 = 'Q1'; $ Q2 = 'Q2'; $ Q3 = 'Q3'; ? & Gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Script type = "text / javascript" & gt; Var Question = New Array ("& lt ;? Php Print ($ Q1) ;? & gt;", "& lt ;? Php Print ($ Q2) ;? & gt;", "& gt; Php Print ( $ Q3);; & gt; "); For (var i = 0; i & lt; = 3; i ++) {warning (question [i]); } & Lt; / Script & gt; & Lt; / Body & gt;
Comments
Post a Comment