【发布时间】:2012-07-21 21:18:18
【问题描述】:
是否可以通过 PHP 函数打开另一个传递 $array 的 PHP 文件(print_array.php)?
HTML:
<form method=post>
<input type="checkbox" name="array[]" value="111">
<input type="checkbox" name="array[]" value="222">
<input type="checkbox" name="array[]" value="333">
<button type="submit" name="action" value="print">Print</button>
<button type="submit" name="action" value="delete">Delete</button>
<button type="submit" name="action" value="add">Add New</button>
</form>
array[] 都被选中,所以 $array 的值是 111、222 和 333。
那么,PHP函数:
switch ($action) {
case 'print': printing($_post['array']); break; /* open new window */
case 'add': break; /* same window */
case 'delete': break; /* same window */
default: break;
}
function printing($array) {
/* open print_array.php in a new window showing $array value */
}
然后,仅当 action=print 时,在具有 $array 值的新窗口中打开 print_array.php。
if (is_array($array)) {
print_r($array);
} else {
...
}
print_array.php 中的结果是
Array ( [0] => 111 [1] => 222 [2] => 333 )
我不认为 header("Location: print_array.php") 可以传递数组值。 有什么好的方法可以在新窗口中打开另一个 PHP 页面并传递数组值?
【问题讨论】:
-
新窗口有条件地意味着通常涉及 Javascript 而不是 PHP。所以我会说简单的答案是“不”。无需赘述。
标签: php arrays new-window