0

I have a simple form with multi select like this

<select multiple="multiple" name="submitted_category[]" >
<option value="test">test</option>
<option value="tests">tests</option>
<option value="testing">testing</option>
</select>

But when I print_r the array it just prints it as "Array"

Here's the php

$submitted_category = $_POST['submitted_category']; 

if(isset($submitted_category)){
print_r($submitted_category);
}
2
  • I tried that and I get "A" no mater how many items I set Commented Mar 13, 2014 at 18:38
  • Did you try my solution? Commented Mar 13, 2014 at 18:56

2 Answers 2

1

Print the element you wish to return. Example:

print_r($submitted[1]);  // print element at position 1

or:

print_r($submitted[0]);  //index of array.

Try:

var_dump($submitted);

as well.

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

4 Comments

That means you selected tests and it found an array with one value of string(5) (5 characters)
thank you chitowns. So how do I count the number of values in the array is it count($submitted_categories)
I think array_count_values($submitted_category); might work. print_r(array_count_values($submitted_category)); if you want to print it to the screen.
i tried var_dump again and i tried all 3 selections and it always said string(5) Array
0
print_r($submitted_category[0]);

You set your select to be an array of values, so you need to choose which Index you want to print out

Something like this as well may help you see all of the values if you are using more than one select

foreach($submitted_category as $value)
{
   print_r($value);
}

Comments

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.