php_begins Posted September 27, 2011 Share Posted September 27, 2011 my user pm table has a touserarray field which is a serialized array that looks like this: a:1:{s:2:"cc";a:1:{i:15773;s:14:"testusername";}} i know I can unserialize it with the unserialize() function. But I need to extract the value corresponding to 'i' field and the 's' field that has the username. So from the above array, i need to retrieve the value '15773' and 'testusername'. Can someone tell me how? Quote Link to comment https://forums.phpfreaks.com/topic/247955-unserialize-array-and-display/ Share on other sites More sharing options...
AyKay47 Posted September 27, 2011 Share Posted September 27, 2011 unserialize it, search for the specific value in the array.. display it.. Quote Link to comment https://forums.phpfreaks.com/topic/247955-unserialize-array-and-display/#findComment-1273247 Share on other sites More sharing options...
php_begins Posted September 27, 2011 Author Share Posted September 27, 2011 i did unserialize it. $var=unserialize($touserarray); but i am unable to get the right syntax to retrieve the 'i' and 's' values that corresponds to userid and username respectively. Quote Link to comment https://forums.phpfreaks.com/topic/247955-unserialize-array-and-display/#findComment-1273248 Share on other sites More sharing options...
PFMaBiSmAd Posted September 27, 2011 Share Posted September 27, 2011 list($key,$value) = each($var['cc']); Quote Link to comment https://forums.phpfreaks.com/topic/247955-unserialize-array-and-display/#findComment-1273253 Share on other sites More sharing options...
php_begins Posted September 27, 2011 Author Share Posted September 27, 2011 Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/247955-unserialize-array-and-display/#findComment-1273273 Share on other sites More sharing options...
AbraCadaver Posted September 27, 2011 Share Posted September 27, 2011 You didn't unserialize it because it is not valid. Use: error_reporting(E_ALL); ini_set('display_errors', '1'); Because 'testusername' is length 12, it should be: a:1:{s:2:"cc";a:1:{i:15773;s:12:"testusername";}} Then you can use PFMaBiSmAd's method. Quote Link to comment https://forums.phpfreaks.com/topic/247955-unserialize-array-and-display/#findComment-1273275 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.