| Haris |
10-12-2007 04:41 AM |
Setting integer to 0 at start of foreach
PHP Code:
<?php $iNameID=0; $iName=0; foreach($this->aCourse as $iKey => $szValue){ ?>
<div class="course">
<h2><?php echo $szValue['className']; ?></h2>
<h4><a href="schools.php?id=<?php echo $this->aSchool[$iNameID++]['id']; ?>" title=""><?php echo $this->aSchool[$iName++]['name']; ?></a></h4>
<p><span class="title">Start Date:</span> <?php echo $szValue['startDate']; ?></p>
<p><span class="title">End Date:</span> <?php echo $szValue['endDate']; ?></p>
<p><span class="title">Course Type:</span> Handguns</p>
</div>
<?php } ?>
I have an array $this->aCourse and $this->aSchool. The school array values will be echo'ed under the foreach loop of course but I don't want to repeat the values. To avoid this, currently I'm setting the integer to 0 like $iNameID=0; $iName=0; and then using it to echo the values.
PHP Code:
<h4><a href="schools.php?id=<?php echo $this->aSchool[$iNameID++]['id']; ?>" title=""><?php echo $this->aSchool[$iName++]['name']; ?></a></h4>
I don't think this is a correct way. What is the correct way of doing this? :)
|