我导入了一个文本文件,这里是代码:
<?php
$file = fopen("stoplist.txt","r") or die("fail to open file");
$stoplist;
$i = 0;
while($row = fgets($file)){
$data = explode(",", $row);
$stoplist[$i] = $data;
$i++;
}
fclose($file);
print "<pre>";
print_r($stoplist);
print "</pre>"
?>
它的输出如下:
Array
(
[0] => Array
(
[0] => a
)
[1] => Array
(
[0] => able
)
[2] => Array
(
[0] => about
)
[3] => Array
(
[0] => above
)
)
但我真的想要这样的结果:
Array
(
[0] => a
[1] => able
[2] => about
[3] => above
)
你对我的问题有什么建议吗?
答案 0 :(得分:1)
您可以使用array_merge将数组转换为单维数组:
$onedimension= call_user_func_array('array_merge', $stoplist);
print "<pre>";
print_r($onedimension);