$ _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.

在我的表单中,我有名称为photoid []的字段,以便在发送时,它们会在php时自动出现在数组中 访问它们。 p>

在几天前,该脚本已经运行了很长时间。 并且据我所知,我没有更改ini文件中的任何php设置并且根本没有更改脚本。 p>

当我尝试使用 $ _ POST [检索]数组时 'photoid'] code>它返回一个内容为'ARRAY'的字符串,但是如果我使用 $ _ REQUEST ['photoid'] code>访问它,它会将它作为数组正确返回。 是否有一些PHP设置会导致这种情况发生? 正如我所说,我不记得最近改变任何PHP设置导致这个,但我可能会弄错,或者还有其他我错过的东西。 p> div>

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."
";
echo $arr[0]."
";

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

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!