Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 添加+;foreach循环中的每个类1个_Php_Wordpress_Foreach - Fatal编程技术网

Php 添加+;foreach循环中的每个类1个

Php 添加+;foreach循环中的每个类1个,php,wordpress,foreach,Php,Wordpress,Foreach,我在用WordPress做这个网站。 下面我有一个粘贴的循环,我想在每个输出id名称中添加+1 因此,当前ID为ID=“计划1\u价格” 在每次循环之后,我希望它变成id=“plan2\u price”,id=“plan3\u price”等 您可以在每个循环中添加$count并递增它: <table class=" <?php $count=1; $best = rwmb_meta( '

我在用WordPress做这个网站。 下面我有一个粘贴的循环,我想在每个输出id名称中添加+1

因此,当前ID为ID=“计划1\u价格” 在每次循环之后,我希望它变成id=“plan2\u price”,id=“plan3\u price”等


您可以在每个循环中添加$count并递增它:

<table class="
                <?php
                $count=1;
                $best = rwmb_meta( 'tb_table1_bestcss' );
                if (!empty($best)){  echo "highlight-best-" . rwmb_meta( 'tb_table1_bestcss' ) . " ";  }
                $popular = rwmb_meta( 'tb_table1_popularcss' );
                if (!empty($popular)){ echo "highlight-popular-" . rwmb_meta( 'tb_table1_popularcss' ); } 
                ?>
            " border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <?php 
                        $tableheading = rwmb_meta( 'tb_table1_heading', 'type=text' );
                        foreach ( $tableheading as $index => $heading ) { 
                    ?>
                    <th scope="col"> 
                    <h3><?php echo $heading; ?></h3>
                        <p class="sub-heading">
                        <?php 
                                $tablesub = rwmb_meta( 'tb_table1_sub_heading' );
                                if (!empty($tablesub)) {
                                    $tablesubheading = rwmb_meta( 'tb_table1_sub_heading', 'type=text' );
                                    echo $tablesubheading[$index];
                                } 
                            ?>
                        </p>
<!--
    THIS IS THE ID i WOULD LIKE TO ADD +1 TO -- id="plan1_price"
-->
                        <div id="plan<?php echo $count; ?>_price" class="price">
                            <sup>$</sup>
                            <span class="amount">
                                <?php 
                                    $tableprice = rwmb_meta( 'tb_table1_price_heading' );
                                    if (!empty($tableprice)) {
                                        $tablepriceheading = rwmb_meta( 'tb_table1_price_heading', 'type=text' );
                                        echo $tablepriceheading[$index];
                                    } 
                                ?>
                            </span>
                            <small class="per-period">/mo</small>
                        </div>
                        </th>
                    <?php
                            $count++;
                        } 
                    ?>
                </tr>
    </table>

您的意思是像
id=“plan1\u price”
?@FoxRider您永远不应该建议其他用户使用PHP短标记,不是所有服务器/设置都会有此功能enabled@DannyBroadbent
@FoxRider从PHP5.4.0开始,@DannyBroadbent Yea,你是对的,我绝对支持你的方法。我只是没有注意到它只对PHP>=5.4.0有效。我的错(不过,幸运的是,评论无法获得票数。^^谢谢,几分钟后我会接受你的答案。我如何才能使第一次迭代输出为no.1因为使用$Tagsorry no,第一个id会像这样输出
id=“plan\u price”
第二个那样
id=“plan2\u price”
在顶部,你看到了吗
<table class="
                <?php
                $count=1;
                $best = rwmb_meta( 'tb_table1_bestcss' );
                if (!empty($best)){  echo "highlight-best-" . rwmb_meta( 'tb_table1_bestcss' ) . " ";  }
                $popular = rwmb_meta( 'tb_table1_popularcss' );
                if (!empty($popular)){ echo "highlight-popular-" . rwmb_meta( 'tb_table1_popularcss' ); } 
                ?>
            " border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <?php 
                        $tableheading = rwmb_meta( 'tb_table1_heading', 'type=text' );
                        foreach ( $tableheading as $index => $heading ) { 
                    ?>
                    <th scope="col"> 
                    <h3><?php echo $heading; ?></h3>
                        <p class="sub-heading">
                        <?php 
                                $tablesub = rwmb_meta( 'tb_table1_sub_heading' );
                                if (!empty($tablesub)) {
                                    $tablesubheading = rwmb_meta( 'tb_table1_sub_heading', 'type=text' );
                                    echo $tablesubheading[$index];
                                } 
                            ?>
                        </p>
<!--
    THIS IS THE ID i WOULD LIKE TO ADD +1 TO -- id="plan1_price"
-->
                        <div id="plan<?php echo $count; ?>_price" class="price">
                            <sup>$</sup>
                            <span class="amount">
                                <?php 
                                    $tableprice = rwmb_meta( 'tb_table1_price_heading' );
                                    if (!empty($tableprice)) {
                                        $tablepriceheading = rwmb_meta( 'tb_table1_price_heading', 'type=text' );
                                        echo $tablepriceheading[$index];
                                    } 
                                ?>
                            </span>
                            <small class="per-period">/mo</small>
                        </div>
                        </th>
                    <?php
                            $count++;
                        } 
                    ?>
                </tr>
    </table>