1

数か所見ていましたが、見るのが苦手で、この操作を行いたいです

$tpl = new Savant3();
$tpl->Info_.$db_code["name"] = $db_code["info"];
$tpl->display('index.tpl.php');

php echo $this->eprint($this->Info_Name);

出来ますか?。ありがとうございました。

4

2 に答える 2

0

はい、可変変数を使用して完全に実行可能です。クラス関数にアクセスするには、関数名を含む変数を使用します。このことを考慮:

class testClass {
  function randomstring() {
    return 'hello world!';
  }
}

この:

$test = new testClass();

// simulate an arbitrary second half of a string/function name
$random_string = 'string';

// build class name into single variable using arbitrary first half
// of string/function name
$class_name = 'random' . $random_string ;
// use that variable (variable variable)
echo $test->{$class_name}(); // hello world!

あなたの場合:これがクラスプロパティの場合、これを行います:(関数の場合は、を追加します()

$prop_name = 'Info_' . $db_code["name"];
$tpl->{$prop_name} = $db_code["info"];
于 2014-03-10T07:44:46.000 に答える