NoDoze Posted May 4, 2013 Share Posted May 4, 2013 I'm totally stumped...!!! Currently I have: Array ( [0] => row1 [1] => row2 ) Array ( [0] => 17240475 [1] => 17240475 ) Array ( [0] => 28.92 [1] => 165.01 ) Array ( [0] => 2 [1] => 1 ) Array ( [0] => 62.00 [1] => 165.01 ) OR Array ( [0] => Array ( [0] => row1 [1] => row2 ) [1] => Array ( [0] => 17240475 [1] => 17240475 ) [2] => Array ( [0] => 28.92 [1] => 165.01 ) [3] => Array ( [0] => 2 [1] => 1 ) [4] => Array ( [0] => 62.00 [1] => 165.01 ) ) I need this to be grouped by key so that it's like this: [0] => row1 [0] => 17240475 [0] => 28.92 [0] => 2 [0] => 62.00 [1] => row2 [1] => 17240475 [1] => 165.01 [1] => 1 [1] => 165.01 Is it even possible...? Should it be even in a multidimensional array format...? Or am I going about this the wrong way? Any help is appreciated, Thank you very much! Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/ Share on other sites More sharing options...
Jessica Posted May 4, 2013 Share Posted May 4, 2013 For one, you should probably use some keys that mean something. An array can not have two or more values at the same key. Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1428194 Share on other sites More sharing options...
Barand Posted May 4, 2013 Share Posted May 4, 2013 try $data = Array ( 0 => Array ( 0 => 'row1', 1 => 'row2' ) , 1 => Array ( 0 => 17240475, 1 => 17240475 ) , 2 => Array ( 0 => 28.92 , 1 => 165.01 ) , 3 => Array ( 0 => 2 , 1 => 1 ) , 4 => Array ( 0 => 62.00, 1 => 165.01 ) ); $new = array(); foreach ($data as $arr) { foreach ($arr as $k => $v) { $new[$k][] = $v; } } echo '<pre>',print_r($new, true),'</pre>'; Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1428198 Share on other sites More sharing options...
NoDoze Posted May 4, 2013 Author Share Posted May 4, 2013 $data = Array ( 0 => Array ( 0 => 'row1', 1 => 'row2' ) , 1 => Array ( 0 => 17240475, 1 => 17240475 ) , 2 => Array ( 0 => 28.92 , 1 => 165.01 ) , 3 => Array ( 0 => 2 , 1 => 1 ) , 4 => Array ( 0 => 62.00, 1 => 165.01 ) ); $new = array(); foreach ($data as $arr) { foreach ($arr as $k => $v) { $new[$k][] = $v; } } echo '<pre>',print_r($new, true),'</pre>'; This looks like it would work... But I forgot to mention the arrays are coming in as variables...how would I do this...? $data = Array ( 0 => $row ) , 1 => $id ) , 2 => $stat1 ) , 3 => $stat2 ) , 4 => $stat4 ) ); $new = array(); foreach ($data as $arr) { foreach ($arr as $k => $v) { $new[$k][] = $v; } } echo '<pre>',print_r($new, true),'</pre>'; Thanks! Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1428201 Share on other sites More sharing options...
mac_gyver Posted May 4, 2013 Share Posted May 4, 2013 But I forgot to mention the arrays are coming in as variables... i'll bet if you show where this data is actually coming from (query/xml...) and what your code is now, someone could show you a solution that would work for the actual data. Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1428202 Share on other sites More sharing options...
Barand Posted May 4, 2013 Share Posted May 4, 2013 I hate it when when it goes like this This is my problem OK you solved that problem However, this new problem is what I really wanted, how about spending more of your time for free? Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1428206 Share on other sites More sharing options...
NoDoze Posted May 4, 2013 Author Share Posted May 4, 2013 Don't get me wrong, it helped ALOT. They are one in the same, because the values are coming from a form, I'm not sure how to explain it. And I can't just paste code because it's too sensitive, it would be a lot of work to "clean it". I used to come here LONG time ago to get quality help. If I knew I was going to get criticized, I would have never returned. If that's what I'm getting now, no thanks. Great way to discourage and drive away people! I'll figure out a solution using another method. Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1428210 Share on other sites More sharing options...
Jessica Posted May 4, 2013 Share Posted May 4, 2013 They are one in the same, because the values are coming from a form, I'm not sure how to explain it. What does that even mean? If the values are posted in a form, they're in $_POST. And you can use Barand's code exactly. What you're trying to accomplish isn't clear at all though. I used to come here LONG time ago to get quality help. If I knew I was going to get criticized, I would have never returned. If that's what I'm getting now, no thanks. Great way to discourage and drive away people! Wah wah wah. You're asking us to devote our time for free to help you, and you're not asking decent questions. Imagine if your boss came to you and said "Make me a website that displays the current time", and you did it, then he said "Oh but really I meant the time in every time zone and make it display daylight savings time, and make the background cycle through random colors. Wait nevermind since you didn't do it the first time I'll just hire someone else, and not pay you at all." Kind of whiny eh? Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1428212 Share on other sites More sharing options...
NoDoze Posted May 21, 2013 Author Share Posted May 21, 2013 Excuse me...! Who's the one whinning??? Sorrrry for "asking you to devote your free time"...but I never recall asking YOU to devote your precious time! Wow you people are on some high horse! If you're so worried about your free time, why are you even in a "community forum"...??? Or perhaps the status of this forum has changed since the last time I was in here...? Clearly you enjoy your free time bashing, flaming, and criticizing.... Sheeesh, I was stumped, and attempted to throw the issue out there in the "community"...but clearly this was the wrong venue... ...I missed where it said, "for the chosen who are willing to devote their time to the minions." I was looking for some professionals.... "Make me a website that displays the current time", and you did it, then he said "Oh but really I meant the time in every time zone and make it display daylight savings time, and make the background cycle through random colors. Wait nevermind since you didn't do it the first time I'll just hire someone else, and not pay you at all." What does this even have to do with what I'm talking about??? In your example, he would be your BOSS, it would be his prerogative. End of subject. Would you kids like to continue with the flaming...? Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1431431 Share on other sites More sharing options...
Jessica Posted May 21, 2013 Share Posted May 21, 2013 (edited) Thought you left. By the way, if you're totally cool with your boss not paying you because he didn't tell you the requirements, I know someone who's hiring. Edited May 21, 2013 by Jessica Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1431432 Share on other sites More sharing options...
Philip Posted May 21, 2013 Share Posted May 21, 2013 Take a deep breath all. After all - it's just code /thread Link to comment https://forums.phpfreaks.com/topic/277625-multidimensional-array/#findComment-1431441 Share on other sites More sharing options...
Recommended Posts