I think your question does not really express what you are trying to say.
In the way you describe it, you would simply do it this way:
$arr1 = array('id' => 1, 'nome' => 'Joao');
$arr2 = array('id' => 2, 'nome' => 'Maria');
$arrTotal = array($arr1['id'], $arr2['id']);
However, perhaps $arr1
and $arr2
are elements of another array, such as this:
$map = array(
array('id' => 1, 'nome' => 'Joao'),
array('id' => 2, 'nome' => 'Maria'),
array('id' => 7, 'nome' => 'Pedro'),
);
With this structure, your question makes sense because there will actually be an iteration. Without foreach:
$map = array(
array('id' => 1, 'nome' => 'Joao'),
array('id' => 2, 'nome' => 'Maria'),
array('id' => 7, 'nome' => 'Pedro'),
);
$result = array_map(function($a) { return $a['id']; }, $map);