Group PHP Array ()

0

I have the following array ()

Array
(
    [0] => stdClass Object
        (
            [usu_id] => 1
            [mod_base] => 1
            [mod_id] => 4
        )

    [1] => stdClass Object
        (
            [usu_id] => 1
            [mod_base] => 1
            [mod_id] => 3
        )

    [2] => stdClass Object
        (
            [usu_id] => 1
            [mod_base] => 1
            [mod_id] => 2
        )

)

I need to group by the mod_base field. How do I?

    
asked by anonymous 11.06.2017 / 23:01

1 answer

1

For example, you can do a foreach where you store the values in mod_base in a new array and then print it

$new_array = array();
foreach($array as $key => $value){
    if($key == 'mod_base'){
        array_push($new_array, $value);
    }
}

I do not think I'm wrong and this will work and solve your problem.

    
11.06.2017 / 23:39