我想知道这是否可能,如果可能,我应该如何实现:
$this->id
<-- 我有这样的东西。但为了让它更有用,我想要 $this->(并在这里更改值)
例如:我可能有 $this->id $this->allID $this->proj_id
我怎样才能使我实际上拥有 $this->(此处为 $myvariable,其中有一个唯一的名称)
?
最佳答案
你可以简单地使用这个:
$variable = 'id';
if ( isset ( $this->{$variable} ) )
{
echo $this->{$variable};
}
关于php - $this->"variable value"OOP PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7715845/