0

如何在 php 中将数组值从一个页面传递到另一个页面并在另一个页面中检索该数组的值。我已经使用 array_push 函数使用如下循环在数组中插入数据库的值。

array_push($file_names,$row['sVoiceFileName'])));

现在,我想将 $file_array 变量传递到另一个页面。我尝试了下面的代码来传递数组但不起作用。它只在 url 中显示 Array。

echo "<a href='download.php?voice=". $file_names."'> ". "Download All"."</a>";

有没有其他方法可以将数组传递到另一个页面或使用 post 方法。以及如何在另一个页面中检索值。在这里,我尝试将数组中包含的所有文件下载为 zip。为此我有功能

function zipFilesAndDownload($file_names,$archive_file_name,$file_path)

在另一个页面中。我需要将 $file_names 数组传递给该函数。

4

2 回答 2

1

那这个呢?

echo "<a href='download.php?voice=". impode(';', $file_names)."'> ". "Download All"."</a>";

function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
$file_names = explode(';', $file_names);
}

implode/explode 你也可以用 json_encode/json_decode、serialize/unserialize 替换,只是根据你的意愿。

于 2012-04-17T08:40:39.833 回答
0

您可以使用例如函数序列化

并将返回的结果作为 POST 或 GET 参数传递

然后将unserialize函数应用于该值,您将获得原始数组

于 2012-04-17T08:41:10.923 回答