Michdd Posted March 5, 2009 Share Posted March 5, 2009 I use this code to break apart an array into a string: $count = count($array); $count2 = count($array[0]); for ( $i=0; $i < $count; $i++ ) { for ( $i=0; $j < $count2; $j++ ) { $mapStr = $mapStr . outArr[$i][$j] . "-"; } $mapStr = $mapStr . "_"; } It's a 2 dimensional array, then it's broken down into a string. What code would I use if I wanted to reconstruct the string generated from this back into an array? Link to comment https://forums.phpfreaks.com/topic/148155-reconstructing-an-array/ Share on other sites More sharing options...
genericnumber1 Posted March 5, 2009 Share Posted March 5, 2009 To clean up yours: <?php foreach($array as &$value) { $value = implode('-', $value); } $mapStr = implode('_', $array); To do the opposite: <?php $array = explode('_', $mapStr); foreach($array as &$value) { $value = explode('-', $value); } There are shorter ways of doing it, but this is the cleanest I can think of. The best way to break down an array into a string though is to use serialize. Link to comment https://forums.phpfreaks.com/topic/148155-reconstructing-an-array/#findComment-777723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.