如何显示数组的元素,由两个组合在一起


How to display elements of array, grouped by two in one <div>

我有一个元素数组。我需要显示页面上的所有元素,按两个分组在一个'div'中像这样:

<div class='row'>
    <article id='1'>item 1 row 1</article>
    <article id='2'>item 2 row 1</article>
</div>
<div class='row'>
    <article id='3'>item 1 row 2</article>
    <article id='4'>item 2 row 2</article>
</div>

这是我当前的php和html代码:

<?php if ($arg['teasers']) foreach ($arg['teasers'] as $id => $article)
        { ?>
            <div class="shops_<?php echo ($article['show'])?'fair':'draft'; ?> more">     
            <div class="shops_title">
                <a href="<?php echo $arg['linkbase'].'/?id='.$id; ?>"><?php echo $article['title']; ?></a>
            </div>
            <div class="shops_teaser" onclick="window.location='<?php echo $arg['linkbase'].'/?id='.$id ?>'">
                <?php echo $article['teaser']; ?>
            </div>
            <?php show_button_detail(array('uri'=>$arg['linkbase'].'/?id='.$id)); ?>            
            </div>
        <?php 
        } ?>
完美的例子:http://tympanus.net/codrops/category/tutorials/

也许你可以试试这样做:

/* div.more */
div.row {
    display: table-row;
    width: 100%; /* your parent element should specify a width for this to work */
}
/* div.more > div[class^="shops_"] */
div.row > article {
    display: table-cell;
    width: 50%;
}