dennismonsewicz Posted October 6, 2008 Share Posted October 6, 2008 I have had these functions explained once, but I didn't necessarily understand the explanation... Can someone explain how these functions are used and what they are used for? Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/ Share on other sites More sharing options...
genericnumber1 Posted October 6, 2008 Share Posted October 6, 2008 They pretty much turn any object/array/etc into a string that is easily saved in a database, flat file, etc. http://us3.php.net/serialize Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658335 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Share Posted October 6, 2008 It converts an array to a string. You can use serialize() to turn an array into a string and save it into a database, then use unserialize() to turn it back into an array again. Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658337 Share on other sites More sharing options...
dennismonsewicz Posted October 6, 2008 Author Share Posted October 6, 2008 so it would turn this: <?php $arr = array("dog", "cat", "horse"); $ser = serialize($arr); echo $ser; ?> into this: dog, cat, horse Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658463 Share on other sites More sharing options...
genericnumber1 Posted October 6, 2008 Share Posted October 6, 2008 so it would turn this: <?php $arr = array("dog", "cat", "horse"); $ser = serialize($arr); echo $ser; ?> into this: dog, cat, horse No, serialize() isn't meant to be human readable, it's meant to be stored and later read by unserialize(). If you want the output you posted there you would use implode(). echo implode(', ', array("dog", "cat", "horse")); Using your code to just show you what serialize makes it (and to show how it's not to be meant for human consumption) the output of serialize on the array is: a:3:{i:0;s:3:"dog";i:1;s:3:"cat";i:2;s:5:"horse";} Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658467 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 It's human readable if you know what it's saying...=P Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658472 Share on other sites More sharing options...
CroNiX Posted October 6, 2008 Share Posted October 6, 2008 It's human readable if you know what it's saying...=P a:3:{i:0;s:3:"dog";i:1;s:3:"cat";i:2;s:5:"horse";} a:3 =>'this is an array of 3 elements' { => 'start of array' i0;s:3:"dog"; => 'index 0 is a string of 3 characters and its value is 'dog' i:1;s:3:"cat"; => 'index 1 is a string of 3 characters an its value is 'cat' i:2;s:5:"horse"; => 'index 2 is a string of 5 characters and its value is 'horse' } => 'end array' See? Very readable same info you get from var_dump, but more compact. Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658483 Share on other sites More sharing options...
genericnumber1 Posted October 6, 2008 Share Posted October 6, 2008 It's human readable if you know what it's saying...=P Yes, but so is binary. serialize() is not made to be read by human USERS, there are other functions for that (of course I don't have to tell YOU that, Mr. function dictionary). That was my point, not that it couldn't be read. Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658485 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 It's human readable if you know what it's saying...=P Yes, but so is binary. serialize() is not made to be read by human USERS, there are other functions for that (of course I don't have to tell YOU that, Mr. function dictionary). That was my point, not that it couldn't be read. =P Quote Link to comment https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.