在PHP中,变量名说,你有一些像这样的代码:变量函数和PHP
$infrastructure = mt_rand(0,100);
if ($infrastructure < $min_infrastructure) $infrastructure = $min_infrastructure;
//do some other stuff with $infrastructure
$country->set_infrastructure($infrastructure);
$education = mt_rand(0,100);
if ($education < $min_education) $education = $min_education;
//do some other stuff with $education
$country->set_education($education);
$healthcare = mt_rand(0,100);
if ($healthcare < $min_healthcare) $healthcare = $min_healthcare;
//do some other stuff with $healthcare
$country->set_healthcare($healthcare);
是否有这些类似的指令集组合成一个功能的一些方式,可以这样调用:
change_stats("infrastructure");
change_stats("education");
change_stats("healthcare");
基本上,你能在其他变量名和函数名称中使用变量在PHP?
在此先感谢。
你能告诉你如何定义$ the_cat吗? – 2009-10-24 13:20:13
更改了示例,使其更清晰一些。 – 2009-10-24 13:29:23
增加了一些额外的代码,使其更清晰。基本上,我有一系列的变量在类中被全部改变。 – 2009-10-24 13:37:05