Turn multidimensional array into string and then back?
Hey guys/gals
I have a multidimensional array like the following that i need to turn into a comma delimited string to save in a mysql database.
PHP Code:
userItems = [[0,2],[22,4],[32,2],[28,4],[88,2],[76,4],[13,9],[17,45]];
Now thats not a problem, i use this function.
PHP Code:
function JoinUserItems() {
sendItems = userItems.join(",");
trace(sendItems);
}
Now when i use that function it turn my multidimensional array into this string
for me to save to mysql.
PHP Code:
0,2,22,4,32,2,28,4,88,2,76,4,13,9,17,45
Now the problem is how do i change it back to its original form as a multidimensional array.
I tried this,
PHP Code:
function SplitUserItems() {
t = sendItems.split(",");
trace(t);
for(i=0; i< t.length; i++) {
if(i%2) {
trace("odd");
}else{
recieveItems.push(t[i],t[i+1]);
trace("even");
}
}
trace(recieveItems);
}
But im pretty sure it only make it a one dimensional array. But its crucial i have it as a multidimensional array.
Any thoughts?
Thanks in AdvancE