jeff5656 Posted August 18, 2010 Share Posted August 18, 2010 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! Link to comment https://forums.phpfreaks.com/topic/211106-serialize-or-implode/ Share on other sites More sharing options...
kickstart Posted August 18, 2010 Share Posted August 18, 2010 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 Link to comment https://forums.phpfreaks.com/topic/211106-serialize-or-implode/#findComment-1100937 Share on other sites More sharing options...
AbraCadaver Posted August 18, 2010 Share Posted August 18, 2010 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! Link to comment https://forums.phpfreaks.com/topic/211106-serialize-or-implode/#findComment-1100943 Share on other sites More sharing options...
kickstart Posted August 18, 2010 Share Posted August 18, 2010 Hi Yep, I agree. Storing the data in tables designed for it is better. As to the sig, too many years working through CICS dumps on mainframes. All the best Keith Link to comment https://forums.phpfreaks.com/topic/211106-serialize-or-implode/#findComment-1100945 Share on other sites More sharing options...
AbraCadaver Posted August 18, 2010 Share Posted August 18, 2010 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 Link to comment https://forums.phpfreaks.com/topic/211106-serialize-or-implode/#findComment-1100950 Share on other sites More sharing options...
jeff5656 Posted August 18, 2010 Author Share Posted August 18, 2010 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... Link to comment https://forums.phpfreaks.com/topic/211106-serialize-or-implode/#findComment-1100969 Share on other sites More sharing options...
btherl Posted August 18, 2010 Share Posted August 18, 2010 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. Link to comment https://forums.phpfreaks.com/topic/211106-serialize-or-implode/#findComment-1100972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.