I think your question doesn’t really express what you’re trying to say.
The way you describe it, you’d just do it that 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 really will be an iteration. No 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);
And why not
array($arr1['id'], $arr2['id']);
?– felipsmartins
You want to add the
id
of all arrays?– Amanda Lima