开发者

dynamic property call

is there a shorter way to achieve the following:

$i = 1;
$p开发者_StackOverflowrop = 'image' . $i;
$image = $this->getObject->$prop;

I have in mind there was something like

$image = $this->getObject->image{$i};

any ideas?


How about:

$this->getObject->{'image'.$i};


A better solution would be to make an array of all images, and then call it like this:

$this->getObject->image[$i]

This will be faster, and is often much easier to work with than a bunch of different variables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜