Php 分隔记录
如果我有一个while循环来检索记录,我希望能够通过在循环进行时将记录包装在大量记录之后来对记录进行定界,例如 (使用while循环): 但我需要像这样对记录进行分组:Php 分隔记录,php,delimiter,Php,Delimiter,如果我有一个while循环来检索记录,我希望能够通过在循环进行时将记录包装在大量记录之后来对记录进行定界,例如 (使用while循环): 但我需要像这样对记录进行分组: <div class="wrap"> Record 1 Record 2 Record 3 </div> <div class="wrap"> Record 4 Record 5 Record 6 </div> Record 7 记录1 记录2 记录3 记录4 记录5 记录6
<div class="wrap">
Record 1
Record 2
Record 3
</div>
<div class="wrap">
Record 4
Record 5
Record 6
</div>
Record 7
记录1
记录2
记录3
记录4
记录5
记录6
记录7
因此,当它超过3时,应该每3次计数包装一次。$index=0;
$index = 0;
while (...) {
if ($index == 0) {
echo '<div class="wrap">';
} elseif (($index % 3) == 0) {
echo '</div><div class="wrap">';
}
// Output your stuff
$index++;
}
if ($index != 0) {
echo '</div>';
}
而(…){
如果($index==0){
回声';
}elseif(($index%3)==0){
回声';
}
//输出你的东西
$index++;
}
如果($index!=0){
回声';
}
$index=0;
而(…){
如果($index==0){
回声';
}elseif(($index%3)==0){
回声';
}
//输出你的东西
$index++;
}
如果($index!=0){
回声';
}
$index = 0;
while (...) {
if ($index == 0) {
echo '<div class="wrap">';
} elseif (($index % 3) == 0) {
echo '</div><div class="wrap">';
}
// Output your stuff
$index++;
}
if ($index != 0) {
echo '</div>';
}
<?php
// Dummy data
$records = array('1','2','3','4','5','6','7');
// While we have at least 3 records, group them
while (count($records) > 3) {
$subs = array_splice($records,0,3);
print '<div class="wrap">'.implode(PHP_EOL, $subs).'</div>';
}
// Dump the rest
print implode(PHP_EOL, $records)
?>