• 技术文章 >后端开发 >php教程

    使用表单传递关联数组的例子_PHP

    2016-06-01 12:38:15原创419
    今天从

    www.php.net的用户反馈处看到如下警告讲到通过表单传递的关联数组不能被

    each
    ()函数读取我尝试了如下的操作没有发现问题结果完全正确。程序如下



    //test1.php











    //test2.php


    $msg = each($var);

    echo $msg[0],$msg[1],$msg['key'],$msg['value'];

    ?>



    //output is

    8eccbad8e776ephp20008eccbad8e776ephp2000



    原文
    - http://www.php.net/manual/ref.array.php



    garbepat
    @ifrance.com

    08
    -Jan-2001 09:52



    Be careful
    if you want to submit a variable as an associative array.



    If for some reason you use indexes that begin with a number - for instance some dynamically

    display ID number
    :

    <input type="textfield" name="vars[8eccbad8e776e]">

    It seems to be a rare
    case but I needed to code that stuff.

    The bug here comes from the fact the browser
    "urlencodes" the name of the field.



    The
    array is actually transmitted but you can't use the "each()" function on It. However I can

    swear you the array is not empty and - that'
    s worse - the correct data is stored at the correct

    index
    (is knew It making 'echo $vars["8ecc..."]').



    The less boring solution I found is to put an
    "_" before any index.

    Then you will surely find a way to remove it
    - using "preg_replace" for instance.
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:例子 关联 传递 使用 the is to
    上一篇:第十四节命名空间[14]_PHP 下一篇:Zend引擎的发展[15]_PHP

    相关文章推荐

    • PHP 5.4.14 and PHP 5.3.24 released!解决思路 • 请教这个网站有开发模版吗 • 关于超市的安装模块,请告诉回答 • 一段方法,求大神指点上异常 • PHP中装务器变量 $_SERVER 详解

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网