Welcome Guest, Not a member yet? Register   Sign In
Grouping and Sorting Arrays
#1

[eluser]phused[/eluser]
I'm having problems grouping arrays based on the value of an item within an array.

I have the following array:

Array (
[0] => stdClass Object ( [company_id] => 1 [company_name] => My Company [user_id] => 4 [user_email] => [email protected] [user_username] => toni [meta_name] => Toni [meta_surname] => Trivkovic [meta_company_id] => 1 )

[1] => stdClass Object ( [company_id] => 2 [company_name] => Ignited Labs [user_id] => 5 [user_email] => [email protected] [user_username] => nick [meta_name] => Nicolo [meta_surname] => Volpato [meta_company_id] => 2 )

[2] => stdClass Object ( [company_id] => 2 [company_name] => Ignited Labs [user_id] => 6 [user_email] => [email protected] [user_username] => john [meta_name] => John [meta_surname] => Smith [meta_company_id] => 2 )
)

What I would like to do is reconstruct this array so users under the same company are grouped within a company's array. In this example nick and john would be grouped under one array (My Company) and toni would be grouped in another.

I'm aware I would probably have to use the array_push() function within a loop but I'm having issues getting this code working. Does anyone have any samples of code or resources they can link me to which shows users how to work with something like this?

Thanks!


Messages In This Thread
Grouping and Sorting Arrays - by El Forum - 08-12-2009, 04:47 AM
Grouping and Sorting Arrays - by El Forum - 08-12-2009, 08:06 AM
Grouping and Sorting Arrays - by El Forum - 08-12-2009, 08:11 AM
Grouping and Sorting Arrays - by El Forum - 08-12-2009, 08:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB