This article analyzes the usage of the PHP submit post array parameters. Share to everyone for your reference, specific as follows:
First in PHP to send the array from the page to server A, to the same name in multiple spaces on the page, and for the names are required, that is Name= "aa[]", note here to add an array of symbols, so as to be in service-side A to fetch
Copy Code code as follows:
The resulting array.
The deeper question is, suppose I now need to deal with the parameters in post, and then send it to another server, how do I pass the parameter AA?
If no processing is done, after the post request is assembled, Server B will always get an array and cannot fetch the actual value.
The solution now is to serialize the service-side A and then deserialize it after Server B receives it. So the deserialized value is an array, and the same as paragraph a gets.
Serialization of
Copy Code code as follows:
$_post["AA"] =serialize ($_post[aa]);
deserialization
$a = "a:2:{i:0;s:1:\" 1\ "; i:1;s:1:\" 2\ ";}"
; Var_dump (Unserialize ($a));
What is the result:
Array (2) {
[0]=>
string (1) "1"
[1]=>
string (1) "2"
}
The serialized parameter obtained in post has been added with the escape character, which needs to be removed before it can be deserialized successfully
$BB = $_post["AA"];
$BB = Str_replace ("\", ", $bb");
Var_dump (Unserialize ($a));
Well, that's the result you want.
Of course, another problem is that you can pass the array value directly to a space of the page, submitted to the server. This situation also needs to be serialized and deserialized.
Page
<input type= "hidden" name= "AA" value= "<?php Echo Base64_encode (Serialize ($array));? >/>
var_dump (base64_decode unserialize (<pre class= "html" name= "code" >{1}</pre><br> post[' Post_data ']));
Do not know add this base64_encode have what effect, appear to be to encode Chinese?
I hope this article will help you with your PHP programming.