how to pass an array in GET in PHP?

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

can I write this line in HTML?

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

or should I write:

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

how will it be passed?

how should I handle it in the called page?

thanks !!


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

As others have written, you can also serialize and unserialize the array.

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.

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


Use serialize and unserialize PHP function. This function giving you storable (string) version of array type. For more infomation about usage read http://php.net/manual/en/function.serialize.php and http://www.php.net/manual/en/function.unserialize.php