Page 1 of 1

Saving/restoring PHP arrays

Posted: Tue Feb 24, 2004 3:30 am
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?

Posted: Tue Feb 24, 2004 3:37 am
by markl999
Try using serialize and unserialize.

Posted: Tue Feb 24, 2004 3:49 am
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.