在PHP中将文本文件导入一维数组
我导入一个文本文件,代码如下:在PHP中将文本文件导入一维数组,php,arrays,Php,Arrays,我导入一个文本文件,代码如下: <?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
<?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] => a
[1] => able
[2] => about
[3] => above
)
$onedimension= call_user_func_array('array_merge', $stoplist);
print "<pre>";
print_r($onedimension);
你对我的问题有什么建议吗 您可以使用将数组转换为一维数组:
$onedimension=call\u user\u func\u数组('array\u merge',$stoplist);
打印“”;
打印(一维);
$stoplist[$i]=$data[0]
您可以显示您的txt文件,将此值设置为一个活动值,并用“”空格分隔,或者在重新创建控制盘之前使用文件功能吗
$onedimension= call_user_func_array('array_merge', $stoplist);
print "<pre>";
print_r($onedimension);