简体   繁体   English

我可以在PHP中声明一个像$(variable name)这样的变量名吗?

[英]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. 我想获取mysql函数mysql_field_name()的结果字符串(字段名),并将其声明为变量,以便以后在程序中使用它。
For example, like this: 例如,像这样:

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

Here, can I use this statement like this : $(mysql_field_name($result,2)); 在这里,我可以使用如下语句: $(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: 这是您可以在PHP中执行的操作:

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

More info in the PHP manual: Variable variables PHP手册中的更多信息: 变量变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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