I have this javascript function which converts a javascript array into a serialized string for use in php as array.
function js_array_serialize(a) {
var a_php = "";
var total = 0;
for (var key in a) {
++ total;
a_php = a_php + "s:" +
String(key).length + ":\"" + String(key) + "\";s:" +
String(a[key]).length + ":\"" + String(a[key]) + "\";";
}
a_php = "a:" + total + ":{" + a_php + "}";
return a_php;
}
The function above does the work for associative array. But I have a multi-dimensional array and something must be done in the for loop, i can think of an other nested loop.
My javascript array is of this structure:
var a = {
'index': {
'subindex1': 'default',
'subindex2': 'default'
},
'index2': {
'subindex1': 'default',
'subindex2': 'default'
}
};
Any help is appreciated. Thanks!