ballhogjoni Posted January 13, 2012 Share Posted January 13, 2012 the code is simple but the output is wrong. $str = <<<EOF a:2:{s:7:"visible";a:7:{i:0;s:5:"email";i:1;s:5:"print";i:2;s:8:"facebook";i:3;s:4:"digg";i:4;s:11:"stumbleupon";i:5;s:7:"twitter";i:6;s:6:"reddit";}s:6:"hidden";a:0:{}} EOF; echo "<textarea rows='10' cols='90'>";print_r(unserialize($str));echo "</textarea>"; the ouput is Array ( [visible] => Array ( [0] => email [1] => print [2] => facebook [3] => digg [4] => stumbleupon [5] => twitter [6] => reddit ) [hidden] => Array ( ) ) This is wrong I need something like this: array ( 'visible' => array ( 0 => 'email', 1 => 'print', 2 => 'facebook', 3 => 'digg', 4 => 'stumbleupon', 5 => 'twitter', 6 => 'reddit', ), 'hidden' => array ( ), ) What am I doing wrong? How do I fix it? Quote Link to comment https://forums.phpfreaks.com/topic/254968-php-unserialize-adding-brackets-around-array-keys/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2012 Share Posted January 13, 2012 That's the output representation that the print_r statement uses so that you can identify what is what. The array keys are just fine. Quote Link to comment https://forums.phpfreaks.com/topic/254968-php-unserialize-adding-brackets-around-array-keys/#findComment-1307338 Share on other sites More sharing options...
ballhogjoni Posted January 13, 2012 Author Share Posted January 13, 2012 ok...I am trying to copy the output from the browser, but it doesn't work because of the brackets plus the browser parses the strings without the quotes. How can I do this? Basically I want to serialize it after i've made my changes to the unserialized array. Quote Link to comment https://forums.phpfreaks.com/topic/254968-php-unserialize-adding-brackets-around-array-keys/#findComment-1307340 Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2012 Share Posted January 13, 2012 You assign the value that unserialize() returns to a php variable - $arr = unserialize($str); Quote Link to comment https://forums.phpfreaks.com/topic/254968-php-unserialize-adding-brackets-around-array-keys/#findComment-1307341 Share on other sites More sharing options...
ballhogjoni Posted January 13, 2012 Author Share Posted January 13, 2012 ok great. I just used var_dump the variable in a textarea to the browser and that seemed to work. Quote Link to comment https://forums.phpfreaks.com/topic/254968-php-unserialize-adding-brackets-around-array-keys/#findComment-1307342 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.