Jump to content

serialize or implode?


jeff5656

Recommended Posts

Hi

 

Use serialize.

 

Serialize gives you something that isn't really human readable, but using unserialize can give you the array back as an array.

 

Implode just joins the array together into a string (and won't really work with multi dimensional arrays).

 

All the best

 

Keith

Hi

 

Use serialize.

 

Serialize gives you something that isn't really human readable, but using unserialize can give you the array back as an array.

 

Implode just joins the array together into a string (and won't really work with multi dimensional arrays).

 

All the best

 

Keith

 

Yes, however if this is a fixed number of numbers with some significance that you may want to search for etc., then often it may be better to store each number in its own column (assuming a single dimension).  Depends upon what exactly your doing and how you'll use the data.

 

BTW, nice sig kickstart!

I want to store an array in a mysql table.  all of the values in the array are numbers.

Should I serialize or implode?  What's the difference?

Thanks!

These may end up converging at some point :)

http://www.phpfreaks.com/forums/index.php/topic,307718.0.html

It's funny that other thread you mentioned.  I have exclusively used extra tables instead of storing an array, because I never learned how to store and retrieve arrays!  So now I  am trying to use an array to store it instead of making a whole new table in the database.  But I agree using tables in a relational database is much more intuitive to me, but only because that's all I know...

If the array DOES only contain numbers and it's only 1 dimension, I would use implode().  There's an advantage in debugging when you have human readable data, as well as having it take less space.  But be aware that implode() will convert all of false, null and "" to an empty string, so you won't be able to distinguish between those.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.