在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