Reis mit Eis Reis mit Eis - 3 months ago 10
PHP Question

Converting multidimentional array into single array and removing the keys

array (size=1551884)
0 =>
array (size=1)
'entity_id' => string '131813' (length=6)
1 =>
array (size=1)
'entity_id' => string '213808' (length=6)
2 =>
array (size=1)
'entity_id' => string '712885' (length=6)


is it possible to convert it to single array without the key 'entity_id' without a loop?

array
0 =>
131813
1 =>
213808
2 =>
712885


I have tried this one :

call_user_func_array('array_merge', $array)


but somehow is only returning 1 element

UPDATE:

here are the benchmark results from the given answers to this question:

php version > 5.6

array_column: 0.20802903175354
foreach: 0.46231913566589
array_map: 1.021989107132


php version > 7

array_column: 0.079965829849243
foreach: 0.15323305130005
array_map: 0.28970503807068

Answer

This is also possible with array_column.

$result = array_column($your_array, 'entity_id');
Comments