如何通过一个数组中得到PHP?

问题描述:

$idArray = array(1,2,3,4);

我可以写在HTML这一行?

can I write this line in HTML?

<form method='POST' action='{$_SERVER['PHP_SELF']}?arr={$idArray}'>

或者我应该写:

<form method='POST' action='{$_SERVER['PHP_SELF']}?arr[]={$idArray}'>

如何将它传递?

我应该怎么处理它在叫页面?

how should I handle it in the called page?

谢谢!

如果你想传递一个数组作为参数,你就必须添加参数为每个元素。您的查询字符串将变成:

If you want to pass an array as parameter, you would have to add a parameter for each element. Your query string would become:

?arr[]=1&arr[]=2&arr[]=3&arr[]=4

正如其他人写的,你也可以的连载的和的反序列化的数组。

但你真的需要再次进行数据发送到客户端?它看起来像你只需要一种方法来的请求间维持数据的。

But do you really have to send the data to the client again? It looks like you just need a way to persist the data between requests.

在这种情况下,最好是伊莫使用sessions(docs).这也更安全的,因为否则客户端可以修改数据

In this case, it is better imo to use sessions(docs). This is also more secure as otherwise the client could modify the data.