0

I am sending an array through POST via a hidden input on a form. I am using JSON to populate the value of this hidden field with the array that I need to pass. On the form handler I then receive the array. However, when I try to count the number of items on the received array it says it is one. It seems that when I $_POST the received variable has the format of an array ["...","..."] but it not recognized as one. Can I cast it into an array? I used the explode() with the comma delimited but the exploded array maintains the '[' and ']' with the first and last elements of the array.

HTML: (here I am showing an example with the value field already populated)

<input type="hidden" name="uploadFilenames" id="uploadFilenames" value="["64034_397137903702241_1591760198_n.jpg","77089_399984063417625_1968141154_n.jpg"]">

PHP:

$filearray =    $_POST['uploadFilenames'];
$numFiles = count($filearray); 
for($i = 0; $i < $numFiles; $i++) {
    echo $filearray[$i] . "<br />";
}
2
  • 1
    json_decode\encode or serialize\unserialize Commented Mar 3, 2014 at 2:32
  • *serialize/unserialize @Dagon :P Commented Mar 3, 2014 at 2:33

1 Answer 1

1

To parse JSON via PHP you will need to use json_decode()

$filearray = json_decode($filearray);

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

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.