Variable as part of other variable php -
this question has answer here:
- php dynamic variable name 2 answers
i have script:
<?php for($i=1; $i<10; $i++):?> <?php if($this->item->nuotrauka{$i}):?> <div class="vobsmall"> <img src="<?php echo $this->item->nuotrauka{$i}; ?>"/> <?php echo $this->item->nuotrauka{$i}; ?> </div> <?php endif; ?> <?php endfor; ?>
there's 9 variables $this->item->nuotrauka1
, $this->item->nuotrauka2
etc.
as can see here i'm trying call these variables using {i}
number of object variable. hovewer code above returns single char variable , not full variable want. how should write {i}
here want ?
try this:
echo $this->item->{"nuotrauka".$i};
Comments
Post a Comment