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.
精彩评论