Home  >  Article  >  Backend Development  >  Usage of php submit post array parameters

Usage of php submit post array parameters

墨辰丷
墨辰丷Original
2018-06-05 17:06:457241browse

本篇文章主要介绍php提交post数组参数的用法,感兴趣的朋友参考下,希望对大家有所帮助。

代码如下:

$_POST[aa]


得到的为数组。

更深一层的问题是,假设我现在需要对post中的参数进行处理后,再传送给另外一个服务端,对于参数aa,应该怎么传递呢?

如果不做什么处理,拼装完post请求后,服务端b获取到的永远只是Array,无法取到实际值。

现在的解决方案是:现在服务端a进行序列化,然后在服务端b接收后进行反序列化。这样反序列化后的值就是一个数组了,和a段获取到的一样。

序列化

复制代码 代码如下:

$_POST["aa"] =serialize($_POST[aa]);


反序列化

$a = "a:2:{i:0;s:1:\"1\";i:1;s:1:\"2\";}";
var_dump(unserialize($a));

结果是什么呢:

array(2) {
 [0]=>
 string(1) "1"
 [1]=>
 string(1) "2"
}

而在post中获取到的序列化后的参数是有进行添加过转义符的,获取后需要去掉,然后才能反序列化成功

$bb = $_POST["aa"];
$bb = str_replace("\\", '', $bb);
var_dump(unserialize($a));

好了,这样才是你要的结果。

当然,还有一种问题是,你可以直接把数组值传递给页面的某一空间,提交给服务端。这种情况同样需要序列化和反序列化。

页面

<input type="hidden" name="aa" value="<?php echo base64_encode(serialize($array));?>" />
var_dump(base64_decode(unserialize(<pre class="html" name="code">{1}

POST['post_data'])));

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。

相关推荐:

php实现压缩合并js的方法

php中二分法查找算法实例详解

PHP实现星号隐藏用户名,手机和邮箱的方法

The above is the detailed content of Usage of php submit post array parameters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn