Saving/restoring PHP arrays

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kadaan
Forum Newbie
Posts: 2
Joined: Tue Feb 24, 2004 3:30 am

Saving/restoring PHP arrays

Post by kadaan »

I'm trying to save an array into a mysql database. Right now I use var_export($array_var, true) to convert it into a string and store it in the database. This works fine, but I'm having problems restoring it. I've tried $array_var = $database_line["stored_array"], but this just sets it to the string.

Same problem with trying to send arrays with POST...

Is there a simpler way to save/restore an array into a database, and also a way to pass an array through a form?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try using serialize and unserialize.
kadaan
Forum Newbie
Posts: 2
Joined: Tue Feb 24, 2004 3:30 am

Post by kadaan »

It worked!

The only problem I had with it was when sending a serialized() array in a form, it adds slashes to it automatically so you have to stripslashes() on the post data before you unserialize() it.
Post Reply