每次加载页面时,我都需要将数组的内容写入文件...我在 index.php 中创建了数组并将内容推送到另一个 ajax 页面中的数组..但我无法访问全局数组..它显示错误为“未定义的变量$arr”..
这是我的代码..
Index.php page...
<?php
$arr = array();
$ourFileName = "saved_data.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, "");
?>
阿贾克斯页面......
<?php
$name_full = $_GET['name_full'];
$arr = $_GET['$arr'];
array_push($arr,$name_full);
/*------------To create a file-----------------*/
$ourFileName = "saved_data.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
/*---------To save data in the file------------*/
foreach($arr as $key => $value)
{
fwrite($ourFileHandle, $value);
}
fwrite($ourFileHandle, ',');
fclose($ourFileHandle);
echo $name_full;
?>
我还应该怎么做才能使这个数组成为全局...