简体   繁体   中英

Can I declare a variable name like this $(variable name) in PHP?

I want to get the resulting string(field name) of the mysql function, mysql_field_name() and declare that as a variable,so that I can use it later in my program.
For example, like this:

$(mysql_field_name($result,2)) = 2;

Here, can I use this statement like this : $(mysql_field_name($result,2));
Is it a correct variable declaration?
Will it work and will it declare a variable with field name as the variable name?

${mysql_field_name($result,2)} = 2

http://codepad.org/NRok2Cha

This is how you can do what you want in PHP:

$varname = mysql_field_name($result, 2);
$$varname = 2;

More info in the PHP manual: Variable variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM