-1

I have below data while form submit.

{
"formData":[
        {"id":"choice1","name":"Test"},
        {"id":"choice2","name":"Test2"}
        ],
 "uid":"75"
}

I need to parse it in php backend file.

$postdata = file_get_contents("php://input");

$request = json_decode($postdata);

$formData = $request->formData;

$uid = $request->uid;

I can get uid data properly but i am not sure how to get others.

Any advise on this?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Roxx
  • 3,738
  • 20
  • 92
  • 155

1 Answers1

1

Use a loop:

foreach($request->formData as $data) {
  echo $data->id;
  //Do any other operations with each element...
}
Chip Dean
  • 4,222
  • 3
  • 24
  • 36
  • thanks for your answer. let me try this. Voted up. – Roxx Jan 26 '17 at 19:14
  • how can i assign it to dynamic variable. instead of echo i am trying like this 'value'.$i = $data.id where $i is 1234 coming from the loop. – Roxx Jan 26 '17 at 19:58