将数组写入文本文件 [英] Writing an array to a text file
问题描述
我的程序中有一个函数可以将一个数组写入一个文本文件,但是我尝试过的每一种方法都会产生相同的结果:当我打开文件来检查它被写入的内容时,所有它显示的是单词Array。在顶部。这是我完成这项任务所需的最后一步!我尝试了一个foreach循环,一个listeach循环和最简单的解决方案,如下所示:
[PHP]函数saveData($ myFile)
{
if($ file = fopen(" employees.dat"," w")):
$ numElements = count ($ myFile);
for($ i = 0; $ i< $ numElements; $ i ++)
{
fwrite($ file,$ myFile [$ i]);
}
fclose($ file);
else:
echo(打开文件时出错。请重新提交);
echo(" < A HREF =''gradedLab3.htm''>返回表单< / A>");
endif;
} [/ PHP]
这些都没有帮助。有什么建议吗?
myFile)
{
if(
file = fopen(" employees.dat"," w")):
numElements = count(
I have a function in my program to write an array to a text file, but every way I''ve tried results in the same result: when I open the file to check what''s been written to it, all it displays is the word "Array" at the top. It''s the last step I need to finish this assignment! I''ve tried a foreach loop, a listeach loop, and the simplest solution, shown below:
[PHP]function saveData($myFile)
{
if($file = fopen("employees.dat", "w")):
$numElements = count($myFile);
for($i = 0; $i < $numElements; $i++)
{
fwrite($file, $myFile[$i]);
}
fclose($file);
else:
echo("Error in opening file. Please re-submit");
echo("<A HREF =''gradedLab3.htm''>Return to form</A>");
endif;
}[/PHP]
None of these has helped. Any advice?
myFile)
{
if(
file = fopen("employees.dat", "w")):
numElements = count(
这篇关于将数组写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!