从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);
}
答
This should do it:
array_keys($first_array);
答
Use array_keys($first_array)
to get the array of all the keys in the $first_array