I’m thinking of storing data from a form as a string, each answer separated by a pipe. The problem I have is that some answers may come in the form of multiple items. We store the radio button selection along with their corresponding answers e.g.
Question 1 - 1 Answer [A1]
Question 2 - Radio button selected [A2] + 3 form fields
Question 3 - 1 Answer [A3]
So I was thinking of storing the data like:
$str = A1|A2[x,x,x]|A3
The reason I chose to enclose multiple selections in brackets is in order to have it relate to the question.
I think my solution will work but when I come to read the values from the database I’ll use Php’s explode() to get the values into an array.
E.g. explode("|",$str);
Will give:
array(0=>A1, 1=>A2[x,x,x],2=>A3);
Before developing this, what would be the best way of getting the content of [x,x,x] and separating it from array[1]?
Any suggestion will be much appreciated.
Thanks
Alternatively, rather than having your answers as a string then trying to turn them to an array you could start with them in an array then if you need turn them into a string, so you could have:
Then if you do need it as a string you can call:
That way, you get a similar method of access to your solution after you have exploded the string, only you don’t have to deal with trying to split the A2[1,2,3] string further as you can just check if it’s an array instead.