A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Turn multidimensional array into string and then back?

  1. #1
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976

    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() {
        
    sendItems.split(",");
        
    trace(t);
        for(
    i=0it.lengthi++) {
            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

  2. #2
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Just worked it out Please delete this thread.

    Ow i just had to change if anyone cares

    recieveItems.push(t[i],t[i+1]);

    to

    recieveItems.push([t[i],t[i+1]]);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center