javascript - add custom data attribute when php loops for second time
滿天的星座
滿天的星座 2017-06-29 10:08:29
0
2
722
<?php foreach($header as $rowItem): ?>
<tr>
    <?php foreach($rowItem as $headerItem): ?>
        <th data-tablesaw-priority="persist" id="<?= $headerItem['id'] ?>" class="<?= $headerItem['class'] ?>"
        <?= (isset($headerItem['colspan']))?'colspan="'. $headerItem['colspan'] .'"':'' ?>
        <?= (isset($headerItem['rowspan']))?'rowspan="'. $headerItem['rowspan'] .'"':'' ?>
        <?= (isset($headerItem['style']))?'style="'. $headerItem['style'] .'"':'' ?> >
            <?= $headerItem['text'] ?>
        </th>
    <?php endforeach ?>
</tr>

<?php endforeach ?>

This loop will have three <tr> tags. Now you need to add custom attributes to the <th> in the second <tr> tag. How does this need to be written?

滿天的星座
滿天的星座

reply all(2)
typecho

The simplest, if judgment loops out the key

学习ing

Method 1, use foreach, add a count variable, record the number of loops, if $count == 1, do what you need to do next

Method 2, use for, do what you need to do when $i==1

for($i=0;$i<count($header);$i++)
{
    if($i === 1) {
        //
    }else{
        //
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template