jmurch Posted January 25, 2010 Share Posted January 25, 2010 I have a string with two different delimeters that I am trying to explode into a mutli-dimensional array but not having any luck: $r_lines = explode(',',$r); echo "<pre>"; echo print_r(explode('~',$r_lines)); echo "</pre>"; TIA, Jeff Quote Link to comment https://forums.phpfreaks.com/topic/189791-explode-string-into-multi-dimentsional-array/ Share on other sites More sharing options...
jmurch Posted January 25, 2010 Author Share Posted January 25, 2010 Getting closer: $r_lines = explode(',',$r); $i = 0; while ($i <= sizeof($r_lines)) { $r_lines_string = implode('~',$r_lines); $r_detail = explode('~',$r_lines_string); echo "<pre>"; print_r($r_detail); echo "</pre>"; $i++; echo "var i = ".$i; } Quote Link to comment https://forums.phpfreaks.com/topic/189791-explode-string-into-multi-dimentsional-array/#findComment-1001571 Share on other sites More sharing options...
jmurch Posted January 25, 2010 Author Share Posted January 25, 2010 Solved! $r_lines = explode(',',$r); $i = 0; while ($i <= sizeof($r_lines)) { $r_lines_string = $r_lines[$i]; $r_detail = explode('~',$r_lines_string); echo "<pre>"; print_r($r_detail); echo "</pre>"; $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/189791-explode-string-into-multi-dimentsional-array/#findComment-1001573 Share on other sites More sharing options...
salathe Posted January 26, 2010 Share Posted January 26, 2010 Unless I'm missing some finer point, your code could alternately be: $data = explode(',', $r); foreach ($data as $key => $value) { $data[$key] = explode('~', $value); } print_r($data); Quote Link to comment https://forums.phpfreaks.com/topic/189791-explode-string-into-multi-dimentsional-array/#findComment-1001757 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.