Reputation: 89
I have a php object, for example: album. Album has proporties img1, img2, img3
Now i use iteration(loop) for setting it, for example:
for($i=1;$i<3;$i++){
$album->img{$i}="image".$i.".jpg";
}
However, the value cannot be set, so i wondering is there more appropriate approach to do this ?
Thanks
Upvotes: 1
Views: 81
Reputation: 2412
Try this:
for($i=1;$i<3;$i++){
$album->{"img".$i}="image".$i.".jpg";
}
Upvotes: 1