kev@num Posted November 5, 2010 Share Posted November 5, 2010 Hi, I'm not sure if this is a wierd one, I have lots of arrays i'm looping through like this to see them:- for($i=0; $i <count($confirmed); $i++){//loop through print_r_html($confirmed[$i]); } Which shows the following :- Array ( [0] => AAAAAA-BBBBBB [1] => 2 [2] => 2010-09-29 ) Array ( [0] => AAAAAA-BBBBBB [1] => 2 [2] => 2010-09-28 ) Array ( [0] => CCCCCC-DDDDDD-EEEEEE [1] => 3 [2] => 2010-09-29 ) Key 0 is a Groupconcat split by "-" Key 1 shows how many fields are in 0 Key 2 is just the date What I would like to do is split the first array into 2 arrays, the second in 2, and the third into 3 (therefore ungrouping the groupconcat if you will) as such:- First into these two:- Array ( [0] => AAAAAA [1] => 2 [2] => 2010-09-29 ) Array ( [0] => BBBBBB [1] => 2 [2] => 2010-09-29 ) Second into these two:- Array ( [0] => AAAAAA [1] => 2 [2] => 2010-09-28 ) Array ( [0] => BBBBBB [1] => 2 [2] => 2010-09-28 ) Third into these two:- Array ( [0] => CCCCCC [1] => 3 [2] => 2010-09-29 ) Array ( [0] => DDDDDD [1] => 3 [2] => 2010-09-29 ) Array ( [0] => EEEEEE [1] => 3 [2] => 2010-09-29 ) ) I know I can get out the info from the first of the keys in each array by putting this into the loop:- for($i=0; $i <count($confirmed); $i++){//loop through if($i==0){ $seperated[] = explode("-",$confirmed[$i]);//split by "-" } } print_r_html($seperated); but i'm not sure how to copy the other keys at the same time? If anyone has got any ideas that would be great! thanks in advance Kev. Quote Link to comment https://forums.phpfreaks.com/topic/217841-array-help-explode-1st-and-copy-other-keys/ Share on other sites More sharing options...
kev@num Posted November 5, 2010 Author Share Posted November 5, 2010 I'm getting very confused trying to imagine nested arrays in my head! Quote Link to comment https://forums.phpfreaks.com/topic/217841-array-help-explode-1st-and-copy-other-keys/#findComment-1130633 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2010 Share Posted November 5, 2010 What I would like to do is split the first array into 2 arrays, the second in 2, and the third into 3 (therefore ungrouping the groupconcat if you will) ^^^ Then why did you use GROUP BY in the first place? What end result are you trying to achieve, because combining data only to undo it later wastes a lot of processing time. I suspect that you just need to ORDER BY the correct column(s) and iterate over the data in your presentation logic. Quote Link to comment https://forums.phpfreaks.com/topic/217841-array-help-explode-1st-and-copy-other-keys/#findComment-1130635 Share on other sites More sharing options...
kev@num Posted November 5, 2010 Author Share Posted November 5, 2010 Hi thanks for your reply, sorry I probably didn't explain correctly, the data is unfortunately already grouped when I receive it so I can't change this I need to split the values @ AAAAAA, BBBBBB, CCCCCC etc so that I can manipulate this data separately. - It just shouldn't be grouped in the first place, hence my problem! any more help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/217841-array-help-explode-1st-and-copy-other-keys/#findComment-1130637 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2010 Share Posted November 5, 2010 <?php $confirmed[] = Array('AAAAAA-BBBBBB',2,'2010-09-29'); $confirmed[] = Array('AAAAAA-BBBBBB',2,'2010-09-28'); $confirmed[] = Array('CCCCCC-DDDDDD-EEEEEE',3,'2010-09-29'); $seperated = array(); foreach($confirmed as $arr){ $parts = explode('-',$arr[0]); foreach($parts as $part){ $seperated[] = array($part,$arr[1],$arr[2]); } } echo '<pre>',print_r($seperated,true),'</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/217841-array-help-explode-1st-and-copy-other-keys/#findComment-1130640 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.