简体   繁体   English

在PHP中将多维数组转换为二维

[英]Multidimensional array to 2 dimensional in php

Is it possible to easily go from multidimensional array to 2 dimensional without looping through it in php? 是否有可能轻松地从多维数组转换为二维数组而无需在php中循环通过? like [key,[key2,value]] to [key,value] that is from 例如[key,[key2,value]]到[key,value]

$tstAry = array("a"=>array(1,"alpha"),"b"=>array(2,"beta"));

to

$tstAry2 = array("a"=>"alpha","b"=>"beta");

i tried playing with array_keys and array_values but couldn't combine it correctly 我尝试使用array_keys和array_values,但是无法正确组合

$tstAry2 = array_combine(array_keys($tstAry), array_column($tstAry, 1));

This got me the desired result, is there an easier way or this is it? 这给了我想要的结果,是更简单的方法吗? like [][1] 像[] [1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM