If it is an array with only two dimensions, such as the output of a database for example, array_column
is the simplest solution:
<?php
$array = [
['nome' => 'Luis', 'id' => 31],
['nome' => 'Rui', 'id' => 42],
['nome' => 'Joao', 'id' => 113],
['nome' => 'Joaquim', 'id' => 434],
['nome' => 'Jorge', 'id' => 503],
];
var_dump(array_column($array, 'nome'));
// Se quiser, pode aproveitar uma segunda coluna para usar como key do novo array
var_dump(array_column($array, 'nome', 'id'));
Executable example .
Remembering that array_column
is one of the new features of php 5.5, but this function can be easily used in previous versions using a implementation in own php .
If your array has even more dimensions, another way is to use a RecursiveIteratorIterator in SPL of PHP.
<?php
$array = [
['nome' => 'Luis', 'id' => 1],
['nome' => 'Rui', 'id' => 2],
['nome' => 'Joao', 'id' => 3],
['nome' => 'Joaquim', 'id' => 4],
['nome' => 'Jorge', 'id' => 5],
];
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
$nomes = [];
foreach ($iterator as $key => $value)
if ($key == 'nome') $nomes[] = $value;
var_dump($nomes);
Executable Example .