【发布时间】:2015-05-04 13:21:58
【问题描述】:
我有这个数组:
$result = array('description1', 'description2', 'description3', 'description4', 'description5'
我想把这个数组分成这样的 div:
- $result[0] - $result[1] => 把这些放到一个 div 中
- $result[2] - $result[3] => 把这些放到一个 div 中
- $result[4] => 把它放到一个 div 中
我的整个结构
$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>';
}
}
【问题讨论】:
-
你试过了吗?
-
我试试这个
$result = array(); foreach(array_chunk($arrayMatches,2) as $k => $desc) { foreach($desc as $item) { $result[] = $item; } } print_r($result); -
^ 将此添加到您的问题中并展示您的努力!
-
你能用javascript来做吗?
-
您应该明确您的问题与现有材料有何不同(通过提供对现有材料的参考,然后解释在哪个级别不适合您的情况,效果最好)否则它可能会倾向于太宽泛,不清楚你到底在问什么。