troubleshooting Question

Rearrange Arrays in PHP

Avatar of OmniUnlimited
OmniUnlimitedFlag for United States of America asked on
23 Comments4 Solutions538 ViewsLast Modified:
Happy New Year Experts!

I hope this question finds you all well and ready for a fantastic new year.

I'd like to start out simple this year (simple at least to you PHP geniuses out there.)

I have a multidimentional associative array, let's call it $A.  This array can be accessed by using two keys such as $A[$key1][$key2].

Right now, the order of the elements goes something like this:


I would like to create a new array grouping all the "e1" elements together, then the "e2" elements and so on, so that the new array would look something like the following:

$NewArray['e1'] = array($A['first']['e1'], $A['second']['e1'], $A['third']['e1'], etc...);
$NewArray['e2'] = array($A['first']['e2'], $A['second']['e2'], $A['third']['e2'], etc...);
$NewArray['e3'] = array($A['first']['e3'], $A['second']['e3'], $A['third']['e3'], etc...);

What is the simplest, most elegant and efficient solution to this?

Join our community to see this answer!
Unlock 4 Answers and 23 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 23 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros