如何反转数组数据?

Rez*_*eza 0 css php arrays wordpress

我想要数组1,3,5,7,9的布局与数组0,2,4,6,8,10的布局相反右边,描述在左边,并且连续不断。

这是我的function.php代码

<?php
            foreach ( $termchildren as $child ) {
                $term = get_term_by( 'id', $child, $taxonomy_name );
                $image = get_field('featured_image', $term);

                ?>
                <div class="row">
                    <div id="product-cat <?php echo $term->slug ?>">
                        <div class="two-col product-cat-image">
                            <img src="<?php echo $image ?>">
                        </div>
                        <div class="two-col product-cat-details">
                            <?php
                                echo '<h4>'. $term->name .'</h4>';
                                echo '<p>'. $term->description .'</p>';
                                echo '<a class="product-cat-button" href="' . get_term_link( $child, $taxonomy_name ) . '">See Products</a>';
                            ?>
                        </div>
                    </div>
                </div><?php
            } ?>
Run Code Online (Sandbox Code Playgroud)

CSS代码:

.row{
  display: flex;
  margin-left: -10px;
  margin-right: -10px;
  margin-bottom: 15px;
}
.row .col {
  flex: 1;
  padding-right: 10px;
  padding-left: 10px;
}
Run Code Online (Sandbox Code Playgroud)

结果仍然像这样 结果

我的期望是这样的: 期望

小智 5

我们只需要如下更改function.php中的代码。

<?php
    $i=0; 
    foreach ( $termchildren as $child ) {
        $term = get_term_by( 'id', $child, $taxonomy_name );
        $image = get_field('featured_image', $term);
        if($i % 2){ ?>
            <div class="row">
                <div id="product-cat <?php echo $term->slug ?>">
                    <div class="two-col product-cat-image">
                        <img src="<?php echo $image ?>">
                    </div>
                    <div class="two-col product-cat-details">
                        <?php
                            echo '<h4>'. $term->name .'</h4>';
                            echo '<p>'. $term->description .'</p>';
                            echo '<a class="product-cat-button" href="' . get_term_link( $child, $taxonomy_name ) . '">See Products</a>';
                        ?>
                    </div>
                </div>
            </div>
        <?php } else {?>
            <div class="row">
                <div id="product-cat <?php echo $term->slug ?>">
                    <div class="two-col product-cat-details">
                        <?php
                            echo '<h4>'. $term->name .'</h4>';
                            echo '<p>'. $term->description .'</p>';
                            echo '<a class="product-cat-button" href="' . get_term_link( $child, $taxonomy_name ) . '">See Products</a>';
                        ?>
                    </div>
                    <div class="two-col product-cat-image">
                        <img src="<?php echo $image ?>">
                    </div>
                </div>
            </div>
        <?php }
       $i++;
    }
?>
Run Code Online (Sandbox Code Playgroud)

希望现在您能掌握所有一切,并让我知道仍然需要任何帮助。