douzhan8395 2016-04-29 15:38
浏览 22
已采纳

发送POST数组和内存泄漏

When sending an HTTP POST array of text data, for example from a web page with an HTML form and text fields, if we use as the name property of the fields the following array url_alias[id] with id being a positive integer, we receive with PHP:

[url_alias] => Array
    (
        [2644] => url-of-product-ref-123
        [1] => url-of-product-ref-224
    )

how will the server (Apache Linux, for example) handle the POST data? Will it internally prepare an array with 2645 indexes, with a null pointer to all indexes except the index: 1 and the index: 2644, or will it do in other, optimized way? Is the format above correct in terms of efficiency - it is very comfortable for PHP programming, but I am afraid of memory leakages or something.

  • 写回答

1条回答 默认 最新

  • dongou2019 2016-04-29 16:00
    关注

    From 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.

    In your example it holds only two keys with one value assigned to each.

    The manual has examples on how arrays in PHP behave. For example, if you set up the following array:

    $array = array(
             "a",
             "b",
        6 => "c",
             "d",
    );
    

    They keys assigned will be 0, 1, 6 and 7:

    array(4) {
      [0]=>
      string(1) "a"
      [1]=>
      string(1) "b"
      [6]=>
      string(1) "c"
      [7]=>
      string(1) "d"
    }
    

    Please read the manual to learn more.

    UPDATE

    You are also asking how arrays are sent over HTTP. They (arrays) are not. According to W3C specification defined here:

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

    Each enctype has it's own rules too long and extensive to be listed here. Read it there if you wish. The thing is, when PHP receives the encoded data, it automatically decodes indexed form variable names.

    So, to wrap it up, the form data is encoded, sent to PHP and the decoding process is on PHP side.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)