troubleshooting Question

split array into groups

Avatar of ellandrd
ellandrdFlag for Ireland asked on
PHP
3 Comments2 Solutions313 ViewsLast Modified:
I have an array with the following:

Array
(
    [0] => Array
        (
            [PropertyID] => 248
            [UserID] => 28
        )
    [1] => Array
        (
            [PropertyID] => 254
            [UserID] => 28
        )
    [2] => Array
        (
            [PropertyID] => 247
            [UserID] => 28
        )
    [3] => Array
        (
            [PropertyID] => 257
            [UserID] => 30
        )
    [4] => Array
        (
            [PropertyID] => 250
            [UserID] => 4
        )
    [5] => Array
        (
            [PropertyID] => 252
            [UserID] => 3
        )
    [6] => Array
        (
            [PropertyID] => 255
            [UserID] => 4
        )
    [7] => Array
        (
            [PropertyID] => 246
            [UserID] => 31
        )
)

I want to split the array into groups based on the UserID values so my array would output as:

Array
(
    [0] => Array
          (
              [28] => 248
            [28] => 254
            [28] => 247
        )
    [1] => Array
        (
            [30] => 257
        )
    [2] => Array
          (
                [4] => 250
                [4] => 255
            )
      [3] => Array
            (
                  [3] => 252
            )
      [4] => Array
            (
                  [31] => 246
            )
)

Im not sure if the above array structure is correct but you get the idea that I want to split the array into groups....
ASKER CERTIFIED SOLUTION
ncoo

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 3 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 2 Answers and 3 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