doujiepin5547 2011-05-10 16:40
浏览 258
已采纳

$ _POST中的变量以字符串而不是数组的形式返回

In my form i have fields with name photoid[] so that when sent they will automatically be in an array when php accesses them.

The script has been working fine for quite some time until a couple days ago. And as far as i can remember i havent changed any php settings in the ini file and havent changed the script at all.

when i try to retrieve the array using $_POST['photoid'] it returns a string with the contents 'ARRAY', but if i access it using $_REQUEST['photoid'] it returns it correctly as an array. Is there some php setting that would make this occur? As i said i dont remember changing any php settings lately to cause this but i might be mistaken, or is there something else i am missing.

  • 写回答

4条回答 默认 最新

  • duanchi5078 2011-05-10 16:52
    关注

    Raise your error_reporting level to find any potential source. It's most likely that you are just using it wrong in your code. But it's also possible that your $_POST array was mangled, but $_REQUEST left untouched.

    // for example an escaping feature like this might bork it
    $_POST = array_map("htmlentities", $_POST);
    // your case looks like "strtoupper" even
    

    To determine if your $_POST array really just contains a string where you expected an array, execute following at the beginning of your script:

    var_dump($_POST);
    

    And following for a comparison:

    var_dump(array_diff($_REQUEST, $_POST));
    

    Then verifiy that you are really using foreach on both arrays:

    foreach ($_POST["photoid"] as $id) { print $id; }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?