【发布时间】:2018-06-25 07:37:51
【问题描述】:
我想将数组转换为带有换行符的字符串,以实现最简单的文本格式。该数组是 mysql 选择查询的结果,我想我需要一个循环,它使用 implode 函数转换为字符串并用某些东西(即“ * ”)分隔字段,并在每行的末尾添加一个换行符。
样本输出
2018-06-22 * meeting * They didn't want to buy anythin
2018-06-23 * * called and wanted to buy something
2018-06-24 * meeting * Gave specification
我在想这样的事情(但我错了,这就是我问的原因):
$Diary =''; // start with empty string
$array = mysqli_fetch_array($fetch);// fetched already
$length = count($array);
for ($x = 0; $length; $x++ + 3) {
$temparray = // use a temp array for one row only
$Diary = // increment a string until the end of the row, add newline at the end
}
【问题讨论】:
-
你能贴出你试图解决这个问题的代码吗?
-
你能显示示例输出吗?
-
欢迎来到 Stack Overflow。您有示例输入吗?到目前为止,您尝试了哪些代码?
-
convert an array to string with newline characters:一个例子?result of a mysql select query:请向我们展示查询+结果。I suppose I need a loop which uses the implode function (...):告诉我们你尝试了什么?顺便说一句,什么不起作用,我没有看到错误?