jubbs Posted May 25, 2007 Share Posted May 25, 2007 Hi all, Sorry to resort to posting yet another "help me" topic, but im really stuck. This should be so easy, im sure you'll be able to get it *just like that*. eg, $a = "20070524;apple"; $b = "20070524;banana"; $c = "20070524;carrot"; $d = "20070527;dog"; $e = "20070708;elephant"; I am trying to sort the dates from the text, so that similar dates become formatted into a string like: 20070524;apple,banana,carrot 20070527;dog 20070708;elephant Can you please post some code to do this? Whether using an array or string variables, I dont mind. As long as it works, I can get an idea and adapt it to my code. Thanks in advance. Jubbs Link to comment https://forums.phpfreaks.com/topic/52927-solved-this-should-be-easy-but-please-help/ Share on other sites More sharing options...
sasa Posted May 25, 2007 Share Posted May 25, 2007 try <?php $a = "20070524;apple"; $b = "20070524;banana"; $c = "20070524;carrot"; $d = "20070527;dog"; $e = "20070708;elephant"; $set = array($a, $b, $c, $d, $e); $out = array(); foreach ($set as $v) { $a = explode(';', $v); $out[$a[0]][] = $a[1]; } foreach ($out as $k => $v) { $out[$k] = $k.';'.implode(',',$v); } foreach ($out as $v) echo $v, "<br />\n"; ?> Link to comment https://forums.phpfreaks.com/topic/52927-solved-this-should-be-easy-but-please-help/#findComment-261378 Share on other sites More sharing options...
jubbs Posted May 25, 2007 Author Share Posted May 25, 2007 Thanks very much! Link to comment https://forums.phpfreaks.com/topic/52927-solved-this-should-be-easy-but-please-help/#findComment-261385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.