TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Setting integer to 0 at start of foreach (http://www.talkphp.com/general/1296-setting-integer-0-start-foreach.html)

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? :)


All times are GMT. The time now is 06:58 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0