2

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.

2
  • 1
    What does $_GET['photoid'] say? Commented May 11, 2011 at 0:44
  • $_GET['photoid'] is empty as the form method="POST" Commented May 11, 2011 at 0:58

4 Answers 4

3

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!

Sign up to request clarification or add additional context in comments.

Comments

2

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

2 Comments

Use it in your from entry script as top-most command. Then gradually move it to isolate where the array was modified. Only php setting that could potentially introduce it earlier is auto_prepend_file.
Found the problem somehow i had a statement actually setting $_POST dont even know how that got in there...
0

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

2 Comments

Yea i am not using it as a string i am currently dumping the information using var_dump and print_r
Then something else is interfering. But this is not a problem with PHP itself.
0

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

1 Comment

No, it is a string, var_dump and gettype even confirms its a string containing the text ARRAY.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.