#1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,151
    Rep Power
    220

    Muslti dimentional SESSION


    Haylo;

    I wanna do this but php's being a bich "[] operator not supported for strings"...
    PHP Code:
    foreach($data as $val=>$row)
        {
            
    $membership_level $row['membership_level'];
            
    //etc etc
            
    $_SESSION['membership_details'][]=array(
                
    'membership_level' => $membership_level,
                
    'membership_level_id' => $membership_level_id,
                
    'days_from_transaction' => $days_from_transaction
                
    )
        } 
    How can I acheive it?

    Thanks
  2. #2
  3. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,151
    Rep Power
    220
    I actually know how to achieve it but its really boolshet it doesnt make sense why cant use [] for $_SESSION. If that's the case then this shouldn't work either
    PHP Code:
    loop
        
    {
            
    $membership_details[]=array();
        }    
    $_SESSION['membership_level_data'] = $membership_details
  4. #3
  5. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,262
    Rep Power
    9645
    Did you even bother to read the error message? Did you see the part about it telling you that you can't do [] on a string?

    Of course I'm posting 57 minutes later so it's quite possible you already figured that out, but unfortunately you don't inspire any particular degree of confidence for that having happened.
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,760
    Rep Power
    4536
    If you want $_SESSION['membership_details'] to be an array, then declare it as such. $_SESSION['membership_details'] = array(). Then you can [] till your heart's content.

    At some point, you've made $_SESSION['membership_details'] have a string value, so it doesn't know what to do with []. Make it an array if that's what you want.
    -- Cigars, whiskey and wild, wild women. --
  8. #5
  9. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,151
    Rep Power
    220
    For someone with my IQ, this was unfairly difficult to guess. I didn't know PHP looks at sessions as string by default. We expected PHP to be more open minded about $_SESSIONS.
    Last edited by English Breakfast Tea; August 12th, 2017 at 07:38 AM.
  10. #6
  11. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,068
    Rep Power
    4101
    Originally Posted by English Breakfast Tea
    For someone with my IQ, this was unfairly difficult to guess. I didn't know PHP looks at sessions as string by default.
    It doesn't. Somewhere in your code you did:
    Code:
    $_SESSION['membership_details'] = '';
    Or similar to create that array key as a string. Using [] on an un-initialized variable works fine to create it as an array. In order to get the error you got you would have had to already initialize the variable as a string.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo