ccdavies ccdavies - 5 months ago 11
PHP Question

Flattening and remove keys from array

How can I turn a multidimensional array like:

Array ( [0] => Array ( [entry_id] => 1941 ) )


Into

Array ( 1941, ..., ..., ... )


I have tried flattening the array, but the keys are still there.

$a = Array();
foreach($result as $r) $a[] = $r['entry_id'];


I am using PHP.

Answer

A fast and simple solution if you have PHP 5.5+

$result = array_column($yourArray, 'entry_id');

Manual