开发者

Variable in $_POST returns as string instead of array

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 fi开发者_运维知识库le 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.


I had the same problem. When I should recieve array via $_POST, but var_dump sad: 'string(5) "Array"'. I found this happens, when you try use trim() on that array! Double check your code, be sure you're not doing anything else with $_POST!


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; }


If you use an array in a string context then you'll get "Array". Use it in an array context instead.

$arr = Array('foo', 42);

echo $arr."\n";
echo $arr[0]."\n";

Array
foo


$_POST['photoid'] is still an array. Just assign it to a variable, and then treat it like an array. ie: $array = $_POST['photoid']; echo $array[0];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜