我遇到了一个大问题,我无法解决问题, 所以我有我的阵列:
Array
(
[0] => Array
(
[id] => 34
[groupe_id] => 4
[object_id] => 4
)
[1] => Array
(
[id] => 35
[groupe_id] => 4
[object_id] => 5
)
)
现在我想创建另一个数组调用$ test以获取此forme中的数组:
Array
(
[object_id] = 4
[object_id] = 5
)
我试过但没有结果:
$test = array();
foreach($aObjectsGroupe as $object){
$test[] = array(
'object_id' => $object['object_id']
);
}
答案 0 :(得分:0)
您不能在PHP数组中包含相同键的重复项。它有点扼杀了钥匙的目的。我想不出有相同键的原因,因为无论如何你都无法通过键引用数组的单个元素,因为它不止一个。
为什么不创建一个名为$ object_ids的数组,并且只有另一个数组中所有object_ids的正常索引数组?
$object_ids = array();
foreach ($aObjectsGroupe as $object) {
$object_ids[] = $object['object_id'];
}