Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-29-2012, 11:50 PM   PM User | #1
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
multidimensional associative array to string and back

I have a multidimensional associative array like so:

PHP Code:
$cartArray 
    
(
        
=> array
        (
            
'product' => 'dvd',
            
'contract' => '2133782'
        
), 
        
=> array
        (
            
'product' => 'music',
            
'contract' => '2131572'
        
),
    ); 
I am currently using http_build_query() to convert to string like so:
$_SESSION['items'] = http_build_query($cartArray);


That seems to be all fine and dandy, but I have no idea how to properly convert it back to an array upon page refresh or moving anto another array.

What can I do to convert my session variable back to such an array?

Thanks for the help
surreal5335 is offline   Reply With Quote
Old 06-29-2012, 11:58 PM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,896
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
you would probaby use parse_str() to pull the data back out but this is easier, err ok not easier but probably a more common approach ....
PHP Code:
<?
$_SESSION
['items'] = serialize($cartArray);
?>
//when you need it next...
<?
$cartArray
=unserialize($_SESSION['items']);
?>
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:46 AM.


Advertisement
Log in to turn off these ads.