These are the json data. name
and vals
are always fix, but the values are generated dynamically.
[
{
"name": "language",
"vals": [
"en",
"de",
"it",
"es"
]
},
{
"name": "currency",
"vals": [
"usd",
"eur"
]
}
]
I now need to convert this json data to a PHP array to store this data in the database, however this data needs to be grouped for later use. Using json_decode
I created an array:
array(2) {
[0]=>
array(2) {
["name"]=>
string(22) "language"
["vals"]=>
array(4) {
[0]=>
string(2) "en"
[1]=>
string(2) "de"
[2]=>
string(2) "it"
[3]=>
string(2) "es"
}
}
[1]=>
array(2) {
["name"]=>
string(22) "currency"
["vals"]=>
array(2) {
[0]=>
string(3) "usd"
[1]=>
string(3) "eur"
}
}
}
I can save the array in the database, but I can't save the data in the DB according to the following scheme:
name1 | vals1 | name2 | vals2
language | en | currency | usd
language | en | currency | eur
language | de | currency | usd
language | de | currency | eur
language | it | currency | usd
language | it | currency | eur
language | es | currency | usd
language | es | currency | eur
Does anyone have a solution for this?