php 销毁 post,PHP-发送POST数组和内存泄漏

当发送文本数据的HTTP POST数组时(例如,从具有HTML表单和文本字段的网页中),如果我们使用ID为正整数的以下数组url_alias [id]作为字段的name属性,则会收到使用PHP:

[url_alias] => Array

(

[2644] => url-of-product-ref-123

[1] => url-of-product-ref-224

)

服务器(例如Apache Linux)将如何处理POST数据?它会在内部准备一个包含2645个索引的数组,并使用空指针指向除index:1和index:2644以外的所有索引,还是以其他优化的方式来做呢?上面的格式在效率方面是否正确-对于PHP编程来说很舒服,但是我担心内存泄漏或其他问题.

解决方法:

从PHP manual开始:

An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.

在您的示例中,它仅持有两个键,并且每个键都分配了一个值.

该手册提供了有关PHP中数组行为的示例.例如,如果您设置以下数组:

$array = array(

"a",

"b",

6 => "c",

"d",

);

它们分配的键将是0、1、6和7:

array(4) {

[0]=>

string(1) "a"

[1]=>

string(1) "b"

[6]=>

string(1) "c"

[7]=>

string(1) "d"

}

请阅读手册以了解更多信息.

更新

您还询问如何通过HTTP发送数组.他们(数组)不是.根据W3C规范定义的here:

The form data set is then encoded according to the content type specified by the enctype attribute of the FORM element.

每个enctype都有自己的规则,时间太长且范围太广,无法在此处列出.如果您愿意,请在此处阅读.事实是,当PHP接收到编码数据时,它会自动解码索引形式变量名称.

因此,要包装起来,将表单数据编码,发送到PHP,并且解码过程在PHP端进行.

标签:memory,post,arrays,php

来源: https://codeday.me/bug/20191118/2030364.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值