duankang5882 2014-02-14 16:57
浏览 40
已采纳

从2D阵列传输密钥以填充1D阵列

PHP has plenty of useful functions and Im wondering if Im overlooking one that has already been built.

Lets say you have an array such as:

$first_array = array("Name"=>"Angela", "Age"=>24);

and you wanted to grab the keys from the first array to create a second array (which could then be pushed into a third array). So you need to create:

$second_array = array("Name", "Age");

Is there a way to achieve this result without this loop?:

foreach($first_array as $k=>$v){
    array_push($second_array, $k);
}
  • 写回答

2条回答 默认 最新

  • douxi8119 2014-02-14 16:59
    关注

    This should do it:

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

报告相同问题?