如果您不想使用会话,则可以将页面包含在另一个文件中。
文件1.php
<php
$arr = array();
$arr['one'] = "one value here";
$arr['two'] = "second value here";
$arr['three'] = "third value here";
?>
文件2.php
<?php
include "file1.php";
print_r($arr);
?>
如果数组是动态创建的并且您想通过 GET 或 POST 传递它,您应该在服务器端形成 URL 并将用户重定向到 HTTP URL 页面而不是 php 文件。
所以像:
文件1.php
<php
$arr = array();
$arr['one'] = "one value here";
$arr['two'] = "second value here";
$arr['three'] = "third value here";
$redirect = "http://yoursite.com/file2.php?".http_build_query($arr);
header( "Location: $redirect" );
?>
文件2.php
<?php
$params = $_GET;
print_r($params['one']);
print_r($params['two']);
print_r($params['three']);
?>