我想将每个博客帖子添加到一个数组中,但我不希望每个新行都在一行中。为什么我希望它成为一个数组是因为我希望在每个博客文章与implode('the space element', $array);
之间获得一个空格,而不是在页面上的最后一篇博文中。
我不想要的内容:
$array[] = '<section id="title"><header><a href="...
我想要的是什么:
# TITLE
$array[] = '<section id="title">';
# TEXT
$array[] .= '<header>';
$array[] .= '<a href="'.url('post/'.date('Y/m/d', strtotime($post['datetime_published'])).'/'.(int)$post['id']).'">';
$array[] .= $post['data_title'];
$array[] .= '</a>';
$array[] .= '</header>';
and so on...
正如您所看到的,我已经尝试了一次可能的解决方案,但如果我这样做,网站看起来不那么好。
我怎样才能完成我的目标?
答案 0 :(得分:0)
你的代码实际上每次只向数组中添加另一个元素,而不是对字符串进行仲裁。
$array[] = 'start ';
$array[] .= 'some text';
将输出
array(2) {
[0]=>
string(6) "start "
[1]=>
string(9) "some text"
}
我认为您要做的是将文本添加到变量中,然后将变量添加到数组中。
这样做:
$text = 'start ';
$text .= 'some text';
$array[] = $text;
将输出:
array(1) {
[0]=>
string(15) "start some text"
}
我会让你把它放在具有正确值的循环中。