I'm trying to make a form with a bunch of questions which can be added to a radioBox, checkBox etc. I have made a .json file containing the questions and possible answers like this (this is just a small part of the file):
{
"questions": {
"0": {
"question":"How many products?",
"answers":["Less than 1000", "More than 1000", "More than 10000"],
"score":[1, 2, 3],
"info":"This is additional information for question 1"
}
,
"1":{
"question":"How many websites?",
"answers":["One", "Two", "Three"],
"score":[1, 2, 3],
"info":"This is additional information for question 2"
}
}
}
I use a class in which I have several functions to make array's which can be used on my regular .php page. I have made an array of questions using the following piece of code, which works:
$questions = [];
foreach($json['questions'] as $key => $value){
$this->questions[] = $value['question'];
}
Now I can just use question[0] to get the first question and question[1] for the second, which is really nice. What I am trying to do is create an array that contains all the answers per question so I can do something similar with the answers. Ideally, it would look something like this:
array:
arrayQuestion1Answers:
string: answer1
string: answer2
string: answer3
arrayQuestion2Answers:
string: answer1
string: answer2
string: answer3
That way I could do something like arrayQuestion1[0] to get the first answer from the first question, and arrayQuestion2[2] to get the third answer from the second question.
Thank you for reading my long (and possibly stupid) question, hope you can help!
$json['questions'][0]['answers'][0]