php - Variable inside curly brackets -


i know how execute php variable inside quotes

$q1 = 1; $q2 = 2; $q3 = 3; $q4 = 4; $q5 = 5;  echo "${q1}"; //outputs 1 

how can output them in loop?

for($i=1; $i<=5; $i++) {     echo "${q$i}"; //how make $i work here? } 

how make $i work along $q?

update

i want quotes there, because creating string in loop , want pass loop mysql query. want string

$str = '$q1, $q2, $q3'; 

and when pass mysql query should interpret values of $q1, $q2, $q3 1,2,3

mysql_query("insert users (col1, col2, col3) values ($str)");  

so should become

mysql_query("insert users (col1, col2, col3) values (1,2,3)"); 

it example know syntax of mysql_query wrong know

i think looking this:

<?php  $arr = array();  $q1 = 1; $q2 = 2; $q3 = 3; $q4 = 4; $q5 = 5;  for($i=1; $i<=5; $i++) {     $arr[] = ${"q".$i};  }  $str = implode($arr, ',');  print_r($str); 

outputs:

1,2,3,4,5 

in action: http://codepad.org/ep7srat5


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -