douao1579 2016-08-23 14:46
浏览 42
已采纳

将多维数组转换为单个数组并删除键

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
  • 写回答

2条回答 默认 最新

  • dsnpjz6907 2016-08-23 14:53
    关注

    This is also possible with array_column.

    $result = array_column($your_array, 'entity_id');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?