php - How to restructure the array so is possible to store each answer and question_id in the answers table?

Solution:
You need to manipulate your original code in such a way that you will get the desired format via that code only.
But if you don't have control on that code, then try to manipulate your current array structure to make it in desired format using below code:-
$final = array();
foreach($array['participant'] as $key=>$val){
$final['participant'][$key]['name'] = $val['name'];
$final['participant'][$key]['surname'] = $val['surname'];
$answer_array = array_column($val,'answer');
$question_id_array = array_column($val,'question_id');
if(is_array($answer_array) && count($answer_array) >0){
$final['participant'][$key]['answer'] = $answer_array;
}
if(is_array($question_id_array) && count($question_id_array) >0){
$final['participant'][$key]['question_id'] = $question_id_array;
}
$final['participant'][$key]['rtypes'] = $val['rtypes'];
}
print_r($final);
Output:-https://eval.in/1048496
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot use isset() on the result of an expression (you can use "null !== expression" instead)
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.