dro62273 2015-05-04 13:21
浏览 32

将数组拆分为div [duplicate]

This question already has an answer here:

I have this array :

$result = array('description1', 'description2', 'description3', 'description4', 'description5'

I want to split this array into divs like this :

  • $result[0] - $result[1] => put these into a div
  • $result[2] - $result[3] => put these into a div
  • $result[4] => put this into a div

My entire structure

$content = get_the_content();
                $description = array();
                $j=0;  


                    if (preg_match_all('/<div id="description" class="description">([^<]*)<\/div>/', $content, $match)) {


                        for( $i = 0; $i < count($match[0]); $i = $i+1 ) {

                            $description[] = $match[0][$i];

                        }

                    }       

                    $attachments =& get_children($args);    
                    $arrayMatches = array();

                        if ($attachments) {
                            foreach(array_chunk($attachments, 2) as $img) {
                                echo '<div class="two_cols">';
                                foreach($img as $attachment) {
                                    foreach($attachment as $attachment_key => $attachment_value) {
                                        $imageID = $attachment->ID;
                                        $imageTitle = $attachment->post_title;
                                        $imagearray = wp_get_attachment_image_src($attachment_value, $size, false);
                                        $imageAlt = get_post_meta($imageID, '_wp_attachment_image_alt', true);
                                        $imageURI = $imagearray[0]; // 0 is the URI
                                        $imageWidth = $imagearray[1]; // 1 is the width
                                        $imageHeight = $imagearray[2]; // 2 is the height
                                ?>

                                <div class="col_1_2">

                                        <!-- A picure Here -->
                                        <?php $arrayMatches[] = $match[0][$j]; ?>

                                </div>


                            <?php

                            break;

                        }

                        $j++;

                    }

                        $arrayMatches = array_chunk($arrayMatches, 2);
                        echo "<div>";
                         foreach($arrayMatches as $v) {
                            echo implode($v);
                        }
                        echo "</div>";

                echo '</div>';

            }       

        }
</div>
  • 写回答

3条回答 默认 最新

  • duanfu3390 2015-05-04 13:24
    关注

    Can you not just echo them in divs:

    <div>
        <?php echo $result[0] . "-" . $result[1]; ?>
    </div>
    <div>
        <?php echo $result[2] . "-" . $result[3]; ?>
    </div>
    <div>
        <?php echo $result[4]; ?>
    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思