kostakondras Posted February 13, 2017 Share Posted February 13, 2017 Hi, I am creating an import using WP All Import in Wordpress and I've been told by their support that I have to write some custom code to create a nested serialised PHP array. The serialised array has to end up looking like this: s:287:"a:8:{s:5:"price";a:2:{s:5:"value";s:5:"38000";s:8:"original";s:0:"";}s:17:"custom_tax_inside";s:0:"";s:15:"custom_tax_page";s:0:"";s:8:"city_mpg";a:1:{s:5:"value";s:0:"";}s:11:"highway_mpg";a:1:{s:5:"value";s:0:"";}s:12:"custom_badge";s:0:"";s:5:"video";s:0:"";s:10:"short_desc";s:0:"";}"; Can you give me any advice on how I can: a) See what this nested serialised array actually looks like b) How I can code a nested serialised array like this Once I can do this I plan to put it into a hook for when WP All Import is importing and this will allow me to import certain values (like price) into my car database. Any input from anyone in the community would be much appreciated. Bonus Point: I have another field that containst he following serialised array: a:7:{i:0;s:38:"Multi-function Control Screen - Colour";i:1;s:17:"11 Speaker Stereo";i:2;s:15:"Online Services";i:3;s:19:"18inch Alloy Wheels";i:4;s:21:"Power - Tailgate/Boot";i:5;s:45:"Power Door Mirrors - Auto Dipping (Reversing)";i:6;s:13:"Driving Lamps";} When I put this into 'http://www.unserialize.com/' I get the following: 'Array ([0] => Multi-function Control Screen - Colour[1] => 11 Speaker Stereo[2] => Online Services[3] => 18inch Alloy Wheels[4] => Power - Tailgate/Boot[5] => Power Door Mirrors - Auto Dipping (Reversing)[6] => Driving Lamps)' However when I type in the following: s:287:"a:8:{s:5:"price";a:2:{s:5:"value";s:5:"38000";s:8:"original";s:0:"";}s:17:"custom_tax_inside";s:0:"";s:15:"custom_tax_page";s:0:"";s:8:"city_mpg";a:1:{s:5:"value";s:0:"";}s:11:"highway_mpg";a:1:{s:5:"value";s:0:"";}s:12:"custom_badge";s:0:"";s:5:"video";s:0:"";s:10:"short_desc";s:0:"";}"; I get the following: s:287:"a:8:{s:5:"price";a:2:{s:5:"value";s:5:"38000";s:8:"original";s:0:"";}s:17:"custom_tax_inside";s:0:"";s:15:"custom_tax_page";s:0:"";s:8:"city_mpg";a:1:{s:5:"value";s:0:"";}s:11:"highway_mpg";a:1:{s:5:"value";s:0:"";}s:12:"custom_badge";s:0:"";s:5:"video";s:0:"";s:10:"short_desc";s:0:"";}"; I just get a string with no array values - what am I doing wrong? Is there something wrong with the serialised array above? Quote Link to comment https://forums.phpfreaks.com/topic/303179-coding-a-nested-serialized-php-array/ Share on other sites More sharing options...
Solution Barand Posted February 13, 2017 Solution Share Posted February 13, 2017 Yes - it has been serialized twice. Serialize the array into a string Serialize the resulting string To unravel it, unserialize twice print_r( unserialize(unserialize('s:287:"a:8:{s:5:"price";a:2:{s:5:"value";s:5:"38000";s:8:"original";s:0:"";}s:17:"custom_tax_inside";s:0:"";s:15:"custom_tax_page";s:0:"";s:8:"city_mpg";a:1:{s:5:"value";s:0:"";}s:11:"highway_mpg";a:1:{s:5:"value";s:0:"";}s:12:"custom_badge";s:0:"";s:5:"video";s:0:"";s:10:"short_desc";s:0:"";}"'))); Gives Array ( [price] => Array ( [value] => 38000 [original] => ) [custom_tax_inside] => [custom_tax_page] => [city_mpg] => Array ( [value] => ) [highway_mpg] => Array ( [value] => ) [custom_badge] => [video] => [short_desc] => ) 1 Quote Link to comment https://forums.phpfreaks.com/topic/303179-coding-a-nested-serialized-php-array/#findComment-1542681 Share on other sites More sharing options...
kostakondras Posted February 13, 2017 Author Share Posted February 13, 2017 Aight - thanks. I'll try and do the import again - this has helped a lot. Quote Link to comment https://forums.phpfreaks.com/topic/303179-coding-a-nested-serialized-php-array/#findComment-1542720 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.