0

I have a big problem and I can't resolve it, So I have my array :

  Array
(
[0] => Array
    (
        [id] => 34
        [groupe_id] => 4
        [object_id] => 4
    )

[1] => Array
    (
        [id] => 35
        [groupe_id] => 4
        [object_id] => 5
    )

 )

Now I want to create another array call $test for get the array in this forme:

Array
(
  [object_id] = 4
  [object_id] = 5
)

I tried but no results:

$test = array();
    foreach($aObjectsGroupe as $object){
        $test[] = array(
            'object_id' => $object['object_id']
        );
    }
Harea Costea
  • 275
  • 5
  • 19

1 Answers1

0

You can't have duplicates of the same key in a PHP array. It kind of defeats the purpose of keys. I can't think of a reason to have identical keys, as you would be unable to reference an individual element of the array by key anyways, because there are more than one.

Why not just make an array called $object_ids, and just have a normal indexed array of the all of the object_ids from the other array?

$object_ids = array();

foreach ($aObjectsGroupe as $object) {
    $object_ids[] = $object['object_id'];
}