elpaisa Posted July 17, 2008 Share Posted July 17, 2008 Hi! I have a string like this stored in a cookie, 1{2,3,4,5,6,7}.2{8,10,20,12,} , I want to split this string in an array, where the first number represents a parent for each group of {}. and each number of the group split it into an array that can use in a for loop, this is a string built for products options in a shopping cart, if any of you know another good method to store the product options, please tell me. Thnx! All your help is needed and welcome!. Link to comment https://forums.phpfreaks.com/topic/115308-solved-complex-array-here/ Share on other sites More sharing options...
effigy Posted July 17, 2008 Share Posted July 17, 2008 Is this what you're after? <pre> <?php echo $str = '1{2,3,4,5,6,7}.2{8,10,20,12,}'; $pieces = preg_split('/[.{}]/', $str, -1, PREG_SPLIT_NO_EMPTY); $count = 0; foreach ($pieces as $piece) { if ($count % 2 == 0) { $result[$piece] = preg_split('/,/', $pieces[$count+1], -1, PREG_SPLIT_NO_EMPTY); } ++$count; } echo '<hr>'; print_r($result); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/115308-solved-complex-array-here/#findComment-592818 Share on other sites More sharing options...
elpaisa Posted July 17, 2008 Author Share Posted July 17, 2008 yes man, it is, thanks, but do you know how to rebuild the array into a new string Link to comment https://forums.phpfreaks.com/topic/115308-solved-complex-array-here/#findComment-592823 Share on other sites More sharing options...
effigy Posted July 18, 2008 Share Posted July 18, 2008 This is now locked because you chose to post in another forum. Link to comment https://forums.phpfreaks.com/topic/115308-solved-complex-array-here/#findComment-593422 Share on other sites More sharing options...
Recommended Posts