为此使用 foreach。在此处查看更多信息 - http://php.net/manual/en/control-structures.foreach.php。
例子 -
$array = Array("333", "222", "111");
foreach($array as $string) {
echo $string.'<br />';
}
另一种解决方案是使用内爆。
在这里查看更多信息 - http://php.net/manual/en/function.implode.php和一个小例子 -
$array = Array("333", "222", "111");
$strings = implode(",", $array); // comma in first quotes are seperator, you can set it also to " " for a single space.
echo $strings; // In this case it will output 333,222,111 if you would set it to empty space then it would output 333 222 11
编辑:
要写入文件,您必须使用文件函数。
检查此链接 - http://php.net/manual/en/function.file-put-contents.php
例子 -
// your file
$file = 'sample.txt';
$array = Array("333", "222", "111");
// Add all strings to $content.
foreach($array as $string) {
$content .= $string.'<br />';
}
// write everything in file
file_put_contents($file, $content);
建议:
当您编写 SQL 查询时,我建议您现在已经开始学习正确地编写它们,因此它们更易于阅读。
例如,您的查询 -
select val from test
可以改成——
SELECT `val` FROM `test`
这更容易阅读和理解。