0

I'm working on a multidimensional array. How can i group it by value ? In the following array [0][1] have same group_id. In this case i want to group these together.

Array
(
    [0] => stdClass Object
        (
            [id] => 142
            [city_name] => Abhayapuri
            [state_id] => 4
            [group_id] => 2
        )

    [1] => stdClass Object
        (
            [id] => 494
            [city_name] => Achabbal
            [state_id] => 15
            [group_id] => 2
        )

    [2] => stdClass Object
        (
            [id] => 1302
            [city_name] => Achhnera
            [state_id] => 34
            [group_id] => 1
        )
)

Is there any way to achieve it.

2
  • Iterate over the array and put each object inside another array that corresponds to its group id. Did you try something like that? Commented May 19, 2014 at 9:57
  • @Jon I've tried but all i'm getting is Cannot use object of type stdClass as array Commented May 19, 2014 at 10:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.