循环前打印计数?

时间:2011-08-30 10:44:27

标签: php loops

<div class="biz_gary_btn fl width81 mt10">
  <div class="pl10 pr10" onclick="javascript:catsub();">Subscribe</div>
 </div>
 <div class="arial bold fnt12 c2f4792 underline fl pl20 pt5"><?php echo $count; ?> Feeds</div>// Here I am going to print my count !!!! but the count will be incremented here
</div>
</div>



<div id="arrow_content" class="fl cl pl10 arial bold fnt11 c2f4792 answer width500">
<div class="clearfix pb10"><!--Subscribe 2nd loop starts here -->
<div class="fl">
   <div class="fl"><img src="images/orange_tab.png" /></div>
   <div class="fl pl10 c666">Feeds on this Bundle</div>
</div><?php foreach($cat['sub_category'] as $sub_cat) 
{           //echo ($count);
?>  
                <style>
                        #subscribe_chk<?php echo $sub_cat['id'];?>.checked{
                           background: url(<?php echo base_url();?>images/pre_checked.jpg) no-repeat;
                           background-position:0px 2px;
                        }
                </style>
<div class="cl pre_check fl pt10">
   <input id="sub_chk<?php echo $sub_cat['id'];?>" value="<?php echo $sub_cat['id'];?>" name="sub_id" onclick="send_value(this.value)" type="checkbox" />
   <label id="subscribe_chk<?php echo $sub_cat['id'];?>" for="sub_chk<?php echo $sub_cat['id'];?>" class="pl5" style="background-color:#FFFFFF;" ><?php echo $sub_cat['sub_category'];?></label>
</div>

<?php $count++; ?>// here I am incrementing the count. How do i print it before the loop
<?php } ?>

2 个答案:

答案 0 :(得分:0)

echo count($cat['sub_category']);
foreach($cat['sub_category'] as $sub_cat) {
    ...

答案 1 :(得分:0)

echo count($cat['sub_category']);

是正确的